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
22
server.py
22
server.py
|
@ -603,13 +603,21 @@ async def connectServer(hostname: str, port: int):
|
||||||
|
|
||||||
async def runServer(address: str, port: int):
|
async def runServer(address: str, port: int):
|
||||||
global G
|
global G
|
||||||
if ":" in address:
|
sock = None
|
||||||
INET = socket.AF_INET6
|
try:
|
||||||
else:
|
if ":" in address:
|
||||||
INET = socket.AF_INET
|
INET = socket.AF_INET6
|
||||||
sock = socket.socket(INET, socket.SOCK_STREAM)
|
else:
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Reuse socket
|
INET = socket.AF_INET
|
||||||
sock.bind((address, port))
|
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)
|
server = await asyncio.start_server(handleClient, sock=sock)
|
||||||
log(f"Listening on port {port}...")
|
log(f"Listening on port {port}...")
|
||||||
G.msgs.append(log("Server startup"))
|
G.msgs.append(log("Server startup"))
|
||||||
|
|
Loading…
Reference in a new issue