Re: Server implementation using custom transport

233 views
Skip to first unread message

Peter Thorson

unread,
Jun 18, 2021, 7:01:44 PM6/18/21
to WebSocket++, Paul Schgor
Hi Paul,

WebSocket++ was architected with the express goal of allowing this sort of use. While most library users have been interested in having all the batteries included it is always nice to see people making use of the pluggable transports.

The short answer to your question is that after constructing a connection (using endpoint::get_connection, as you correctly noted) you will need to call the connection::start() method to signal to the connection that you are done constructing and setting connection specific handlers and options and are ready to feed it data. At this point the connection can be fed data with read_some, etc You will need to also register a write_handler, but guessing you know that if you have a client already working.

On the client side are you calling endpoint::connect on the connection you get back from get_connection() by chance? If so, that will automatically call start for you.

If you haven't found it yet, there is a bundled example (iostream_server) that demonstrates the use of the iostream transport in a server context (including things like placement of connection::start). Note that this example focuses on the iostream based I/O which is handy when building tools that read and write websocket streams to standard in/out but probably is less interesting if you are reading and writing to TCP sockets unless your socket code happens to expose itself as C++ iostreams. You can use read_some and the write handler as a complete replacement for istream input and registering an ostream for output.

Best,

Peter

On 2021-06-18, at 11:21, Paul Schgor <pauls...@gmail.com> wrote:

Hi,

I'm sure I'm just missing the point somewhere, as setting up a websocket Client using our own socket code (unfortunately I am unable to use ASIO in my project) was so easy, but I am struggling to to handle the initial handshake received from the client in my server implementation.

So far I have created my endpoint based on typedef websocketpp::server<websocketpp::config::core>, in my socket code received a TCP connection from the client and created a new connection calling get_connection(). I have then setup message, http and fail handler. I was then assuming I could pass call read_some() on the websocket++ connection with the data my client just sent me, but the state of m_reading is false and also my m_state is connecting, not open.

I'm assuming I am missing the vital part of actually informing the websocket++ connection that we have a TCP connection and are ready to run? 

If anyone has any suggestions as to what I'm missing, I'd be very grateful!

Thanks,
Paul

--
You received this message because you are subscribed to the Google Groups "WebSocket++" group.
To unsubscribe from this group and stop receiving emails from it, send an email to websocketpp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/websocketpp/f93cd8b6-5ac7-4bc4-84da-612b1e1b1c99n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages