-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreceiver.py
More file actions
23 lines (19 loc) · 776 Bytes
/
receiver.py
File metadata and controls
23 lines (19 loc) · 776 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import socket
recv_ip="192.168.1.57"
recv_port=4444 # 0 - 1024 -- you can check free udp port netstat -nulp
# creating udp socket
# ip type v4 , uDp
s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM) # socket takes 2 inputs first for address family(ipv4 or ipv6 and another one for place connection either tcp or udp)
# fitting ip and port with udp socket
s.bind((recv_ip,recv_port))
# recv data from sender
while 4 > 2 :
data=s.recvfrom(100)
# converting byte-like to string
ndata=data[0].decode('ascii')
print("message from sender ",ndata)
print("sender IP + port --socket ",data[1])
# reply to sender
rply=input("type your rply : ")
s.sendto(rply.encode('ascii'),data[1])
s.close()