forked from Firepup650/python-talk
Fallback to IPv4 when IPv6 is unsupported when using the default address (::1)
This commit is contained in:
parent
aaeb313181
commit
a44e7c29fd
1 changed files with 15 additions and 7 deletions
|
@ -603,6 +603,8 @@ async def connectServer(hostname: str, port: int):
|
|||
|
||||
async def runServer(address: str, port: int):
|
||||
global G
|
||||
sock = None
|
||||
try:
|
||||
if ":" in address:
|
||||
INET = socket.AF_INET6
|
||||
else:
|
||||
|
@ -610,6 +612,12 @@ async def runServer(address: str, port: int):
|
|||
sock = socket.socket(INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Reuse socket
|
||||
sock.bind((address, port))
|
||||
except OSError as E:
|
||||
if E.errno != 97 or hostname != '::1':
|
||||
raise E
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Reuse socket
|
||||
sock.bind(('0.0.0.0', port))
|
||||
server = await asyncio.start_server(handleClient, sock=sock)
|
||||
log(f"Listening on port {port}...")
|
||||
G.msgs.append(log("Server startup"))
|
||||
|
|
Loading…
Reference in a new issue