JuliaWeb / WebSockets.jl

A WebSockets library for Julia
MIT License
157 stars 58 forks source link

Question: Passive server #160

Closed skrobec closed 1 year ago

skrobec commented 3 years ago

Im sorry but i don´t know where to ask. Is it possible to do passive websocket Julia server ? My situation is following. Need Julia to be running and wait for connection from javascript, but so far when trying examples, julia programs ends right away. Is there a way to stop execution till connection is established ? Same like in usual C socket listen function lets say. Basically passive wait. Thanks for help.

hustf commented 3 years ago

The way creators of the websocket protocol imagined it, the websocket connection would be established in two steps: First, a server is set up, waiting for connections from a http browser. A html page would be served from the server to the browser. Javascript contained in that html page would run in the browser/ client. The javascript would send a request to the same server, asking if the server would agree to upgrade the connection from a tcp connection to a websocket connection.

If the upgrade request is successful, the websocket connection stays open until it breaks for some reason, or either side initiates a closing handshake as defined by the websocket protocol. This can actually be quite confusing - there is no rule set to the actual conversation. This is why you can also define a subprotocol. But if websockets are used as originally intended, the server hands the javascript code to the browser / client and thus has every chance of knowing the "protocol" to follow.

Perhaps your server is actually running as a background task? Perhaps you could try one of the examples and post the output in this issue? Good luck!