def connectToServer(host, port, data): HOST = host PORT = port print data s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT)) s.send(serialization.serializable(data)) data = s.recv(1024) s.close() print 'Received: ', serialization.deserializable(data)
import serialization # Echo server program import socket HOST = '' # Symbolic name meaning all available interfaces PORT = 50007 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((HOST, PORT)) s.listen(1) conn, addr = s.accept() print 'Connected by', addr while 1: data = conn.recv(1024) if not data: break print 'data:', data data = serialization.deserializable(data) conn.send(data) conn.close() if __name__ == '__main__': pass