from Util import *
from BitTorrentClientRun import *
-PORT = 10001
+PORT = 10005
HOST = "127.0.0.1"
-
BUFFER_SIZE = 4096
states = {} # keeps track of what kind of message was previously receveid on a socket.
bt_client_data[TORRENT])
btcr.start()
- btcr.run_client(btcr.simple_run_command)
-
+ pid = btcr.run_client(btcr.simple_run_command)
+ return pid
+
+ return -1
"""Simple test
btcr = BitTorrentClientRun("/usr/bin/transmissioncli",
btcr.start()
btcr.run_client(btcr.simple_run_command)
"""
+
+def stop_bt_client(pid):
+ os.kill(pid, signal.SIGKILL) # kill generates zombies
+ os.wait()
+ print "killed ", pid
+
def doServer():
- #os.spawnvp(os.P_NOWAIT,"/usr/bin/transmission",[])
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+
+ print HOST
+ print PORT
serversocket.bind((HOST, PORT));
serversocket.listen(10) #max 10 requests
if states[clientsock] == WAITING_START_DATA:
bt_client_data = recv_pickled_data(clientsock)
- start_bt_client(bt_client_data)
+ client_pid = start_bt_client(bt_client_data)
+ clientsock.send(ACK_MSG +" "+ str(client_pid))
elif states[clientsock] == WAITING_STOP_DATA:
- config = recv_pickled_data(clientsock)
+ client_pid = recv_pickled_data(clientsock)
+ stop_bt_client(client_pid)
+ clientsock.send(ACK_MSG)
elif states[clientsock] == WAITING_STATUS_DATA:
config = recv_pickled_data(clientsock)
+ clientsock.send(ACK_MSG)
states[clientsock] = WAITING_MSG_TYPE
-
# clientsock.recv(BUFFER_SIZE)
# recv_pickled_data(clientsock)
- clientsock.send(ACK_MSG)
- print "am trimis ack"
- clientsock.close()
+
+ clientsock.close()
if __name__ == "__main__":
doServer()