--- /dev/null
+import sys, socket
+MSGLEN = 100
+
+
+class MySocket:
+ def __init__(self, sock=None):
+ if sock is None:
+ self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ else:
+ self.sock = sock
+
+ def connect(self, host, port):
+ self.sock.connect((host, port))
+ print "connected to %s %s"%(host, port)
+
+ def send_msg(self, msg):
+ totalsent = 0
+ while totalsent < len(msg):
+ sent = self.sock.send(msg[totalsent:])
+ if sent == 0:
+ raise RuntimeError, "socket connection broken"
+ totalsent = totalsent + sent
+
+ def recv_msg(self):
+ msg = ''
+ chunk = self.sock.recv(MSGLEN)
+ if chunk == '':
+ raise RuntimeError, "socket connection broken"
+ msg = msg + chunk
+ print msg
+ return msg
+
+
+if __name__ == "__main__":
+
+ s = MySocket()
+ s.connect("127.0.0.1", 10001)
+ s.send_msg("hello")
+ s.recv_msg()
+
+
+
+
+
# TODO: listen, receive on port
-import sys, time, os
+import sys, os, socket
from daemon import Daemon
def doServer():
+ #os.spawnvp(os.P_NOWAIT,"/usr/bin/transmission",[])
+ serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
+ serversocket.bind(("127.0.0.1", 10001));
+ serversocket.listen(10) #max 10 requests
+ while(1):
+ (clientsock, address) = serversocket.accept();
+ clientsock.recv(100)
+ clientsock.send("Hello :)")
+ clientsock.close()
- os.spawnvp(os.P_NOWAIT,"/usr/bin/transmission",[])
class MyDaemon(Daemon):
def run(self):