Cliente de echo


/ Published in: Python
Save to your folder(s)



Copy this code and paste it in your HTML
  1. import socket
  2. import sys
  3.  
  4. host = 'localhost'
  5. port = 50000
  6. size = 1024
  7. s = None
  8.  
  9. if (len(sys.argv)>0):
  10. message = sys.argv[1]
  11. else:
  12. message = "Hello, World!"
  13.  
  14. try:
  15. s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  16. s.connect((host,port))
  17. except socket.error,(value,errmessage):
  18. if s:
  19. s.close()
  20. print "Could not open socket: " + errmessage
  21. sys.exit(1)
  22. s.send(message)
  23. data = s.recv(size)
  24. s.close()
  25. print 'Received: ',data

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.