Posted By

cirio on 05/06/08


Tagged

server chat


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

mustapha


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.