-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
30 lines (24 loc) · 688 Bytes
/
client.py
File metadata and controls
30 lines (24 loc) · 688 Bytes
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
import socket
HEADER_SIZE = 64
PORT = 3000
FORMAT = "utf-8"
DISCONNECT_MESSAGE = "!DISCONNECT"
# run server.py to check the ip address and update as required
SERVER_IP_ADDRESS = "192.168.0.102"
REMOTE_ADDRESS = (SERVER_IP_ADDRESS, PORT)
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(REMOTE_ADDRESS)
def send(msg):
message = msg.encode(FORMAT)
msg_length = len(message)
send_length = str(msg_length).encode(FORMAT)
send_length += b' ' * (HEADER_SIZE - len(send_length))
client.send(send_length)
client.send(message)
send("Hello!")
input()
send("How are you?")
input()
send("Thank you, take care!")
input()
send(DISCONNECT_MESSAGE)