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):
|
async def runServer(address: str, port: int):
|
||||||
global G
|
global G
|
||||||
|
sock = None
|
||||||
|
try:
|
||||||
if ":" in address:
|
if ":" in address:
|
||||||
INET = socket.AF_INET6
|
INET = socket.AF_INET6
|
||||||
else:
|
else:
|
||||||
|
@ -610,6 +612,12 @@ async def runServer(address: str, port: int):
|
||||||
sock = socket.socket(INET, socket.SOCK_STREAM)
|
sock = socket.socket(INET, socket.SOCK_STREAM)
|
||||||
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Reuse socket
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) # Reuse socket
|
||||||
sock.bind((address, port))
|
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