Skip to content

Commit 1cd45d8

Browse files
committed
committed from zkp
1 parent d069497 commit 1cd45d8

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

net编程/02.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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()

net编程/1.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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......")

net编程/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)