File tree Expand file tree Collapse file tree 3 files changed +35
-0
lines changed
Expand file tree Collapse file tree 3 files changed +35
-0
lines changed Original file line number Diff line number Diff line change 1+ import socket
2+
3+ def clientFunc ():
4+ sock = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
5+ text = '你说的啥'
6+ data = text .encode ()
7+ sock = text .encode ()
8+ sock .sendto (data , ("127.0.0.1" , 7852 ))
9+ data , addr = sock .recvfrom (200 )
10+ data = data .decode ()
11+ print (text )
12+
13+ if __name__ == '__main__' :
14+ clientFunc ()
Original file line number Diff line number Diff line change 1+ import socket
2+ def serverFunc ():
3+ sock = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
4+ addr = ("127.0.0.1" , 7852 )
5+ sock .bind (addr )
6+ data , addr = sock .recvfrom (500 )
7+ print (data )
8+ print (type (data ))
9+
10+ text = data .decode ()
11+ print (text )
12+ print (type (text ))
13+
14+ rsp = '我不知道'
15+ data = rsp .encode ()
16+ sock .sendto (data , addr )
17+
18+ if __name__ == '__main__' :
19+ print ("Starting server......." )
20+ serverFunc ()
21+ print ("Ending server......" )
You can’t perform that action at this time.
0 commit comments