socketcluster-client-python icon indicating copy to clipboard operation
socketcluster-client-python copied to clipboard

Socket client is blocking the thread

Open valamorgon opened this issue 6 years ago • 2 comments

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

valamorgon avatar Jan 04 '18 05:01 valamorgon