-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
28 lines (21 loc) · 851 Bytes
/
client.py
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
import socket
def wait(debug):
hostname = socket.gethostname()
IPAddr = socket.gethostbyname(hostname)
if debug == True:
print("Your Computer Name is: " + hostname)
print("Your Computer IP Address is: " + IPAddr)
# Define the server address and port
SERVER_HOST = '127.0.0.1' # localhost
SERVER_PORT = 12345 # Same port as the server
# Create a socket object
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
# Connect to the server
s.connect((SERVER_HOST, SERVER_PORT))
# Send a message to the server
message = "Hello, server!"
s.sendall(message.encode())
print(f"Message sent to server: {message}")
# Receive a response from the server
data = s.recv(1024)
print(f"Response from server: {data.decode()}")