Allow setting socket options

This commit is contained in:
Fierelier 2024-01-17 23:01:27 +01:00
parent c6752502d6
commit 4861357b88
2 changed files with 18 additions and 7 deletions

View File

@ -31,10 +31,11 @@ class serverThread(threading.Thread):
pass
global makeServer
def makeServer(host,port,https):
def makeServer(host,port,https,sockOpts):
print("Opening " +str(host)+ ":" +str(port)+ " (" +str(https)+ ") ...")
serverSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
serverSocket.setsockopt(socket.SOL_SOCKET,socket.SO_REUSEADDR,1)
for sockOpt in sockOpts:
serverSocket.setsockopt(*sockOpt)
serverSocket.bind((host,port))
if https:
proto = False
@ -54,4 +55,4 @@ def makeServer(host,port,https):
serverSocket.listen(65535)
thread = serverThread(serverSocket,not (https == False))
serverThreads.append(thread)
thread.start()
thread.start()

View File

@ -1,8 +1,18 @@
global servers
servers = [
# Host Port SSL Certificate
("127.0.0.1", 61920, False),
# ("127.0.0.1", 443, "localhost.pem")
# Host Port SSL Certificate Socket Options
("127.0.0.1", 61920, False, (
(socket.SOL_SOCKET,socket.SO_REUSEADDR,1),
(socket.IPPROTO_TCP,socket.TCP_NODELAY,1),
(socket.IPPROTO_TCP,socket.IP_TOS,0x10) # IPTOS_LOWDELAY
)
),
# ("127.0.0.1", 443, "localhost.pem", (
# (socket.SOL_SOCKET,socket.SO_REUSEADDR,1),
# (socket.IPPROTO_TCP,socket.TCP_NODELAY,1),
# (socket.IPPROTO_TCP,socket.IP_TOS,0x10)
# )
# )
]
global timeout
@ -14,4 +24,4 @@ enableOutThread = False # Use a seperate thread for data output?
global printExceptions
printExceptions = False # Print exceptions as they happen, enable if you're developing
global clientDebug
clientDebug = False # Print how many clients and threads there are
clientDebug = False # Print how many clients and threads there are