Example for a Websocket Echo-Server
Added by Philipp Lebrenz over 9 years ago
Hello,
my company asked me to investigate serveral C libaries with websocket support, because we want to have websocket support in our projects. Now I'm trying WT and I have already build and tested the hello world example. Now I want to implement a simple echo-websocket server, which should simply return the incoming messages(which are arriving from the client) to the websocket client (implemented in java script). But I have problems to realize that task.
Could someone post a short implementation of the server? It would be a great help!
Thanks in advance,
Philipp
Replies (2)
RE: Example for a Websocket Echo-Server - Added by Wim Dumon over 9 years ago
Hello Philipp,
It's really easy to upgrade hello world (or any other Wt application) into a websocket application. Set true in wt_config.xml. This will make Wt use websockets to communicate with the client whenever websockets are available, falling back to ajax if websockets are not available for some reason.
Wt does not have an interface currently to write your own websockets endpoints. If we'd want to do this, we could do something similar to WResource for websockets, but in general we recommend to use JSignal/slot to communicate between browser and server because they will benefit from the same fallback mechanisms and tie nicely into the Wt event loop.
Best regards,
Wim.
RE: Example for a Websocket Echo-Server - Added by Philipp Lebrenz over 9 years ago
Thank you for your answer!