/ Published in: Python
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
import socket import sys host = 'localhost' port = 50000 size = 1024 s = None if (len(sys.argv)>0): message = sys.argv[1] else: message = "Hello, World!" try: s = socket.socket(socket.AF_INET,socket.SOCK_STREAM) s.connect((host,port)) except socket.error,(value,errmessage): if s: s.close() print "Could not open socket: " + errmessage sys.exit(1) s.send(message) data = s.recv(size) s.close() print 'Received: ',data