Last active
June 29, 2022 09:09
-
-
Save Zheaoli/108546daf349de358761f9f8b9664a53 to your computer and use it in GitHub Desktop.
Connection in Use Case
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
s = socket.socket() | |
host = "127.0.0.1" | |
port = 12345 | |
s.connect((host, port)) | |
print(s.recv(1024).decode()) | |
time.sleep(10000000) | |
s.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import socket | |
import time | |
import os | |
def abc(): | |
s = socket.socket() | |
host = "127.0.0.1" | |
port = 12345 | |
s.bind((host, port)) | |
# print(s.error) | |
s.listen(5) | |
while True: | |
c, addr = s.accept() | |
print("连接地址:", addr) | |
c.send("Manjusaka!".encode()) | |
break | |
s.close() | |
while True: | |
abc() | |
time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@jschwinger233 嗯,是的,最终的解法是 SO_REUSEADDR/SO_REUSEPORT