Skip to content

Socket client is blocking the thread #9

@valamorgon

Description

@valamorgon

When I run the following code, everything works well but the last print("after line") line, not executes unless communication interrupted.

from socketclusterclient import Socketcluster
import logging
logging.basicConfig(format='%(levelname)s:%(message)s', level=logging.DEBUG)

def onconnect(socket):
    logging.info("on connect got called")

def onConnectError(socket,err):
    logging.info(err)
    logging.info("err")

def ondisconnect(socket):
    logging.info("dc")

def onSetAuthentication(socket, token):
    logging.info("Token received " + token)
    socket.setAuthtoken(token)
        
def onAuthentication(socket, isauthenticated):
    logging.info("Authenticated is " + str(isauthenticated))
    socket.emit("sample","hi")
    
if __name__ == "__main__":
    socket = Socketcluster.socket("ws://localhost:8000/socketcluster/")
    socket.setBasicListener(onconnect, ondisconnect, onConnectError)
    socket.setAuthenticationListener(onSetAuthentication, onAuthentication)
    socket.connect()
    print("after line")

And in console I have the following lines and it is stuck

INFO:on connect got called
INFO:{"rid":1,"data":{"id":"EhStRAQxoM9SHSo2AAAG","pingTimeout":20000,"isAuthenticated":false}}
INFO:Authenticated is False
INFO:Emit data is {"data": "hi", "event": "sample"}

My server code is:

scServer.on('connection', function (socket) {

      socket.on('sample', function (data) {
        console.log('Handled sampleClientEvent', data);
      });

    });

And server console:
Handled sampleClientEvent hi

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions