File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1+ import socket
2+ import argparse
3+ import multiprocessing
4+
5+ def client (server , port ):
6+ sock = socket .socket (socket .AF_INET , socket .SOCK_DGRAM , socket .IPPROTO_UDP )
7+ sock .bind ((server , port ))
8+ while True :
9+ payload = sock .recvfrom (1024 )
10+ print (payload [0 ].decode (), end = '' )
11+
12+ if __name__ == "__main__" :
13+
14+ parser = argparse .ArgumentParser (
15+ description = 'UDP Client' )
16+
17+ parser .add_argument ('-server' , type = str , default = "" ,
18+ help = 'Host Name or IP Address of the UDP Server' )
19+
20+ parser .add_argument ('-port' , type = int , default = 10110 ,
21+ help = 'UDP Port Number' )
22+
23+ args = parser .parse_args ()
24+
25+ if (args .server != "" ):
26+ print ("Connecting to " + args .server + " on port " + str (args .port ))
27+ else :
28+ print ("Listening on port " + str (args .port ))
29+
30+ proc = multiprocessing .Process (target = client , args = (args .server , args .port ))
31+ proc .start ()
32+
33+ try :
34+ while True :
35+ pass
36+ except KeyboardInterrupt :
37+ proc .terminate ()
You can’t perform that action at this time.
0 commit comments