I'm attempting to write a game server and I need it to continue on with the code while listening for a connection. I know this is done with the threading module but I don't know how exactly to do this. Python documentation didn't work for me.
#[LISTENER]
print "Initializing Listener..."
Listener.Listen(server_ip, int(server_port))
#(AFTER LISTENER HAS STARTED WAITING FOR A CONNECTION)
os.system("cls")
print "Server IP: %s" % server_ip + ":" + server_port
print "Level Name: %s" % level_name
print "Public IP: %s" % public_ip
print "-------------------------------------------"
os.system("pause")
Listener code
import os, socket
import Interpreter
class Listen:
def __init__(self, server_ip, server_port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((socket.gethostname(), server_port))
s.listen(5)
while 1:
(clientsocket, address) = s.accept()
if clientsocket and address:
Interpreter.newConnection(clientsocket, address)