server - implemented stop client, not working
authorAdriana Draghici <adriana008@gmail.com>
Mon, 15 Feb 2010 15:26:13 +0000 (17:26 +0200)
committerAdriana Draghici <adriana008@gmail.com>
Mon, 15 Feb 2010 15:26:13 +0000 (17:26 +0200)
bt_comm/Util.py
bt_comm/server/Client.py
bt_comm/server/Server_NO_DAEMON.py

index 0fc72a7..1db4fd0 100644 (file)
@@ -1,6 +1,10 @@
 
 #!/usr/bin/env python
 
+
+#PORT = 1002 
+#HOST = "127.0.0.1"
+
 """ Message types: client -> server """
 
 START_MSG = "1";
index e8c9003..939d6f2 100644 (file)
@@ -3,8 +3,7 @@ import pickle
 from Util import *
 MSGLEN = 1024
 HOST = "127.0.0.1"
-PORT = 10001
-
+PORT = 10005
 class MySocket:
        def __init__(self, sock=None):
                if sock is None:
@@ -78,6 +77,9 @@ if __name__ == "__main__":
 
                                }
        response = s.send_command(START_MSG, start_data)
-       print response
-
 
+        
+       print response
+        pid = (response.split())[1]
+        print "pid = ", pid
+        response = s.send_command(STOP_MSG, response)
index ea83ef6..8375649 100644 (file)
@@ -6,9 +6,8 @@ from daemon import Daemon
 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.
@@ -43,8 +42,10 @@ def start_bt_client(bt_client_data):
                                                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", 
@@ -60,10 +61,18 @@ def start_bt_client(bt_client_data):
        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
 
@@ -93,22 +102,24 @@ def doServer():
                
                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()