Jump to content

multithreaded server in python


Recommended Posts

I am re-writting an application I wrote in java in python. The problem I am having is even though I have multi-threaded the server I can only get 1 client to connect each time the server runs. Here is the error I am getting

socket.error: [Errno 104] Connection reset by peer

Here is the server which gets the connection and passes it off to a new thread

def startServer():
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host, port))
    Misc.mmrghPrint("Zombie Server Started")
    while 1:
        Thread(target=ZombieThread.authenticate(s.accept()), args=(s.accept())).start() # <-- Here

Here is the thread that it is passed off to.

def authenticate(socket):
    conn, addr = socket
    zombieIP = Misc.parseAddr(addr)
    # Client to Server Challenge
    ClientSecretNum = 547623564
    key = int(Misc.recvDecrypted(conn, 1024))
    Misc.sendEncrypted(conn, key + ClientSecretNum)          
    # Server to Client Challenge
    ServerSecretNum = 6992825753837
    challengeNum = randint(1111111111111111, 9999999999999999)
    Misc.sendEncrypted(conn, challengeNum)
    respondse = int(Misc.recvDecrypted(conn, 1024))
    if respondse != (challengeNum + ServerSecretNum):
        Misc.mmrghPrint("Could not authenticate zombie from " + zombieIP)
        Misc.mmrghPrint("Zombie connected form " + zombieIP)

Maybe someone here can shed some light onto what my problem is and save me from bashing my head into a wall!

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...