daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import socket
  2. import sys
  3. import time
  4. import threading
  5.  
  6. s = socket.socket()
  7. host = socket.gethostname()
  8. print("Server started on hostname: ", host)
  9. port = 8000
  10. s.bind((host,port))
  11. s.listen(1)
  12. conn, addr = s.accept()
  13. print(addr, "has connected")
  14. def send_Messages():
  15.     while 1:
  16.         message = input(">>")
  17.         message = message.encode()
  18.         conn.send(message)
  19.         print("Message sent")
  20. def receive_Messages():
  21.     while True:
  22.         incoming_message = conn.recv(1024)
  23.         incoming_message = incoming_message.decode()
  24.         print(">> Client: ", incoming_message)
  25.  
  26. incoming_thread = threading.Thread(target=receive_Messages)
  27. incoming_thread.start()
  28. send_thread = threading.Thread(target=send_Messages)
  29. send_thread.start()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top