Posted By

buscarini on 07/14/06


Tagged

socket red servidor


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

anayhk


Servidor de echo


 / Published in: Python
 

  1. import socket
  2. import sys
  3.  
  4. host = ''
  5. port = 50000
  6. backlog = 5
  7. size = 1024
  8. s = None
  9. try:
  10. s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  11. s.bind((host,port))
  12. s.listen(backlog)
  13. except socket.error,(value,message):
  14. if s:
  15. s.close()
  16. print "Could not open socket: " + message
  17. sys.exit(1)
  18. while 1:
  19. client,address = s.accept()
  20. data = client.recv(size)
  21. if data:
  22. print(data)
  23. client.send(data)
  24. if (data=="quit"):
  25. sys.exit(0)
  26. client.close()

Report this snippet  

You need to login to post a comment.