Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Server code: https://pastebin.com/yLRiad1f
- #Client
- import socket
- import threading
- # Client configuration
- HOST = '127.0.0.1' # Server's IP address
- PORT = 12347
- # Function to send messages
- def send_message(client_socket):
- while True:
- message = input("")
- client_socket.send(message.encode('utf-8'))
- # Function to receive and display messages from the server
- def receive_messages(client_socket):
- while True:
- message = client_socket.recv(1024)
- print(">" , message.decode('utf-8'))
- # Main client code
- client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- client.connect((HOST, PORT))
- send_thread = threading.Thread(target=send_message, args=(client,))
- send_thread.start()
- receive_thread = threading.Thread(target=receive_messages, args=(client,))
- receive_thread.start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement