-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
25 lines (18 loc) · 679 Bytes
/
client.py
File metadata and controls
25 lines (18 loc) · 679 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
import socket
from message_wrapper import get_message
import settings
udp_client_socket = socket.socket(
family=socket.AF_INET,
type=socket.SOCK_DGRAM
)
print('UDP client up and ready to send.')
first_message = str.encode('You say: "beep"')
print(first_message)
udp_client_socket.sendto(first_message, settings.SERVER_ADDRESS)
first_response, _ = udp_client_socket.recvfrom(settings.BUFFER_SIZE)
print(first_response)
while True:
message = get_message(settings.PROMPT)
udp_client_socket.sendto(message, settings.SERVER_ADDRESS)
response_from_server, _ = udp_client_socket.recvfrom(settings.BUFFER_SIZE)
print(f'Server says: {response_from_server}')