2018-07-22 19:16:29

Hello developers!
Is anyone able to help with this issue? Basically, i want a python client to connect, and then have an input box with what i want to send, It connects because i get the message saying i connect, but then when i do a loop where it receives and stuff i don't know who to make it keep receiving and have the input box keep popping up to let me send things if that makes any sense.

2018-07-22 20:59:05 (edited by Munawar 2018-07-22 21:02:33)

Sockets are bi-directional communication, so your client and server must be able to read and write data without interruption. You can run your client and server logic on separate threads.

If I was implementing the client side in the libraries I've used in the past, I would execute client.run() on a child thread. You can push data into the socket loop from the outside using an external call provided by the socket library. This way, the data you want to send to the socket is queued in the thread-safe manner and sent over the socket the next time the loop ticks.

The server part is much easier to implement since all you want to do is read data from the client. Execute your server.run() method (as it is commonly called across many socket libraries,) and your callbacks for receiving data from the client will fire when appropriate.

Please check this link. https://github.com/websocket-client/websocket-client

They have a fully running example of a client-server interaction there and are using the threads method I just described; it will be better for you to check this example than me providing you one.

Finally, I gather your sockets are "freezing" as your topic subject describes. This is most likely due to you performing a blocking call and not running the socket loop. Don't perform any long-running blocking operations inside your socket loop or you will block the loop. Without your code, this is the best I can give you. Don't think of socket programming as synchronous; it's best to implement socket solutions asynchronously.