client:
#!/usr/bin/env python#coding:utf-8#author:Bingimport socketclient = socket.socket()ip_port = ("127.0.0.1",9999)client.connect(ip_port)while True: data = client.recv(1024) print data inp = raw_input("data:") client.send(inp) if inp == "exit": break
simple progress:
#!/usr/bin/env python#coding:utf-8#author:Bingimport socketserver = socket.socket()ip_port = ("127.0.0.1",9999)server.bind(ip_port)server.listen(5)while True: conn,address = server.accept() conn.send("hello..!") flag = True while flag: data = conn.recv(1024) print data if data == "1" : conn.send("this is test") elif data == "exit": flag = False else: conn.send("Guess") conn.close()
multipprogress:
#!/usr/bin/env python#coding:utf-8#author:Bingimport SocketServerclass Myserver(SocketServer.BaseRequestHandler): def setup(self): pass def handle(self): while True: conn = self.request conn.send("hello..!") flag = True while flag: data = conn.recv(1024) print data if data == "1" : conn.send("this is test") elif data == "exit": flag = False else: conn.send("Guess") conn.close() def finish(self): pass if __name__ == "__main__": server = SocketServer.ThreadingTCPServer(("127.0.0.1",9999),Myserver) server.serve_forever()
simple ftp server: