Server example [function: chat]


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

http://lineguides.netsons.org


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.