obernardovieira

Chatroom [Client]

Sep 23rd, 2016
368
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.75 KB | None | 0 0
  1. #this is just an example for an article at my wordpress
  2. #check the complete article at http://obernardovieira.byethost18.com
  3. #server side here http://pastebin.com/hPVc7Ds8
  4.  
  5. # Echo client program
  6. from threading import Thread
  7. import socket
  8.  
  9. def waitNewMessage(s):
  10.     data = ''
  11.     while data != 'finish':
  12.         data = s.recv(1024)
  13.         print 'Received', repr(data)
  14.  
  15. HOST = 'localhost'        # The remote host
  16. PORT = 50007              # The same port as used by the server
  17. s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  18. s.connect((HOST, PORT))
  19.  
  20. Thread(target=waitNewMessage, args=(s,)).start()
  21. msg_to_send = ''
  22. while msg_to_send != 'finish':
  23.     msg_to_send = raw_input('What is your message?')
  24.     s.sendall(msg_to_send)
  25.  
  26. s.close()
Add Comment
Please, Sign In to add comment