We Recommend

Learning Python Learning Python
The authors of Learning Python show you enough essentials of the Python scripting language to enable you to begin solving problems right away, then reveal more powerful aspects of the language one at a time. This approach is sure to appeal to programmers and system administrators who have urgent problems and a preference for learning by semi-guided experimentation.


Posted By

cirio on 05/06/08


Tagged

server chat


Versions (?)


Server example [function: chat]


Published in: Python 


http://lineguides.netsons.org

  1. import socket
  2.  
  3. HOST = '127.0.0.1'# Nome simbolico che rappresenta il nodo locale
  4. PORT = 90007 # Porta non privilegiata arbitraria
  5. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6. s.bind((HOST, PORT))
  7. s.listen(6)
  8.  
  9. while 1:
  10. conn, addr = s.accept()
  11. data = conn.recv(1024)
  12. if data=='/quit':
  13. print '...FINE CONNESSIONE CON',addr,'...'
  14. conn.close()
  15. if not data: break
  16. print 'Client',addr,'::. \t'+data
  17. risp=raw_input('Server::. \t')
  18. conn.send(risp)
  19. conn.close()

Report this snippet 

You need to login to post a comment.