Posted By

buscarini on 07/14/06


Tagged

socket desarrollo red cliente


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

anayhk


Cliente de echo


 / Published in: Python
 

  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  

You need to login to post a comment.