Advertisement
LEGEND2004

Client

Oct 21st, 2023 (edited)
1,032
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | None | 0 0
  1. # Server code: https://pastebin.com/yLRiad1f
  2.  
  3. #Client
  4. import socket
  5. import threading
  6.  
  7. # Client configuration
  8. HOST = '127.0.0.1'  # Server's IP address
  9. PORT = 12347
  10.  
  11. # Function to send messages
  12. def send_message(client_socket):
  13.     while True:
  14.         message = input("")
  15.         client_socket.send(message.encode('utf-8'))
  16.  
  17. # Function to receive and display messages from the server
  18. def receive_messages(client_socket):
  19.     while True:
  20.         message = client_socket.recv(1024)
  21.         print(">" , message.decode('utf-8'))
  22.  
  23. # Main client code
  24. client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  25. client.connect((HOST, PORT))
  26.  
  27. send_thread = threading.Thread(target=send_message, args=(client,))
  28. send_thread.start()
  29.  
  30. receive_thread = threading.Thread(target=receive_messages, args=(client,))
  31. receive_thread.start()
  32.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement