def main():
	global endflag
	if len(sys.argv)<>3:
		usage()
		sys.exit()
	else:
		port1 = int(sys.argv[1])
		port2 = int(sys.argv[2])
	
	controlThreads = []	
	try:
		socketServer = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		socketServer.bind(('',port1))
		socketServer.listen(20)
		socketClient = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
		socketClient.bind(('',port2))
		socketClient.listen(20)
	
		clientNum = 0     #the number of client connection.
	
		while True:
			currentLink = clientNum +1
			print "[Link %s] Listening on port %s,waiting for server connect..." % (currentLink,port1)
			serverConn,serverAddr = socketServer.accept()
			print "[Link %s] Server %s connect! " % (currentLink,serverAddr)
			while True:
				print "[Link %s] Listening on port %s,waiting for client connect..." % (currentLink,port2)
				client_Conn,client_Addr = socketClient.accept()
				print "[Link %s] Get a client connection from %s !" % (currentLink,client_Addr)
				serverConn.send('__newLink__') # send current client info,to create a new thread in reprocks_client to connect with current reprocks_server.
				temp = control(serverConn,client_Conn,serverAddr,client_Addr,clientNum)
				temp.setDaemon(True)
				controlThreads.append(temp)
				controlThreads[clientNum].start()
				clientNum += 1
				break
	except __HOLE__:
		print "Catch ctrl+c pressed,program will exit."
		for m in endflag:
			m = True
dataset/ETHPy150Open RicterZ/reprocks/server/reprocks_server.py/main