File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
Expand file tree Collapse file tree 1 file changed +34
-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_STREAM )
7+ sock .connect ((server , port ))
8+ while True :
9+ payload = sock .recv (1024 )
10+ print (payload .decode (), end = '' )
11+
12+ if __name__ == "__main__" :
13+
14+ parser = argparse .ArgumentParser (
15+ description = 'TCP Client' )
16+
17+ parser .add_argument ('-server' , type = str , default = "" ,
18+ help = 'Host Name or IP Address of the TCP Server' )
19+
20+ parser .add_argument ('-port' , type = int , default = 2948 ,
21+ help = 'TCP Port Number' )
22+
23+ args = parser .parse_args ()
24+
25+ print ("Connecting to " + args .server + " on port " + str (args .port ))
26+
27+ proc = multiprocessing .Process (target = client , args = (args .server , args .port ))
28+ proc .start ()
29+
30+ try :
31+ while True :
32+ pass
33+ except KeyboardInterrupt :
34+ proc .terminate ()
You can’t perform that action at this time.
0 commit comments