-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
39 lines (26 loc) · 1.08 KB
/
client.py
File metadata and controls
39 lines (26 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import socket
from threading import Thread
# Define the server host and port to connect to
HOST = '127.0.0.1' # The server's hostname or IP address
PORT = 65432 # The port used by the server
def start_client():
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket:
# Connect to the server
client_socket.connect((HOST, PORT))
print(f"Connected to server at {HOST}:{PORT}")
while True:
# Read user input
# message = input("Enter message to send (or 'exit' to quit): ")
message = "WAVELENGTH "
if message.lower() == 'exit':
print("Closing connection.")
break
# Send message to the server
client_socket.sendall(message.encode('utf-8'))
# Receive the echoed message from the server
response = client_socket.recv(1024)
print(f"Received from server: {response.decode('utf-8')}")
if __name__ == "__main__":
thread1 = Thread( target=start_client, args=() )
thread1.start()
thread1.join()