toko214

chat client

Oct 3rd, 2016
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.79 KB | None | 0 0
  1. import socket
  2. import thread
  3.  
  4. HOST,PORT=('my ip',8200)
  5. con_socket=socket.socket()
  6.  
  7.  
  8. def main():
  9.     try:
  10.         con_socket.connect((HOST,PORT))
  11.         thread.start_new_thread(recv_msg,())
  12.         while True:
  13.             msg=raw_input()
  14.             print "You Wrote: "+msg
  15.             con_socket.send(msg)
  16.     except socket.timeout:
  17.         print "connection failed"
  18.         con_socket.close()
  19.     except socket.error:
  20.         print("connection dropped")
  21.         con_socket.close()
  22.     con_socket.close()
  23.  
  24.  
  25. def recv_msg():
  26.     while True:
  27.         try:
  28.             msg=con_socket.recv(1024)
  29.             print msg
  30.         except socket.error:
  31.             con_socket.close()
  32.             break
  33.     con_socket.close()
  34. if __name__ == '__main__':
  35.     main()
  36.     con_socket.close()
Add Comment
Please, Sign In to add comment