8000 Update udpServer.py · mikephp/basic_data_struct@39a58ff · GitHub
[go: up one dir, main page]

Skip to content 65F1

Commit 39a58ff

Browse files
authored
Update udpServer.py
modify for socket port reuse
1 parent e46092f commit 39a58ff

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/python/socket/udp/srv-cli-demo-2/udpServer.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
from time import ctime
33

44
HOST = ''
5-
PORT = 20123
5+
# convert to network port
6+
PORT = htons(514)
7+
#PORT = 20123
68
BUFSIZ = 128
79
ADDR = (HOST, PORT)
810

911
udpServer = socket(AF_INET, SOCK_DGRAM)
10-
12+
# port reuse
13+
udpServer.setsockopt(SOL_SOCKET,SO_REUSEADDR,1)
1114
udpServer.bind(ADDR)
1215

1316
while True:
@@ -18,4 +21,4 @@
1821
udpServer.sendto('[%s] %s' % (ctime(), data), addr)
1922
print '...received from and returned to:', addr,data
2023

21-
udpServer.close()
24+
udpServer.close()

0 commit comments

Comments
 (0)
0