-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUDP9999.py
More file actions
33 lines (24 loc) · 908 Bytes
/
UDP9999.py
File metadata and controls
33 lines (24 loc) · 908 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
31
32
33
import sys
import socket
clientS = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
dataSize = 2048
HOST = '192.168.1.101' #Jorge's PI
PORT = 6454
address = (HOST, PORT)
if sys.argv[1:] == ['server']:
clientS.bind(address)
print("Listening at %s" %clientS.getsockname())
while True:
data, address = clienS.recvfrom(dataSize)
print("The client is at %s and said: %s" %(address, data.decode()))
clientS.sendto("The data you sent me was %d bytes long from %s".encode() %(len(data), address))
elif sys.argv[1:] == ['client']:
clientS.sendto("Hi server!".encode(), address)
data, address = clientS.recvfrom(dataSize)
print("The server is at %s and said: %s" %(address, data.decode()))
temp = 10
while (temp != 0):
clientS.sendto("Hi Server: ".encode(), address)
temp = temp -1
else:
print("Usage: sANDc.py client|server")