zaphoyd / websocketpp

C++ websocket client/server library
http://www.zaphoyd.com/websocketpp
Other
7.05k stars 1.97k forks source link

Examples of non-asio network transport #631

Open alexflint opened 7 years ago

alexflint commented 7 years ago

I understand that websocketpp has multiple transports, one of which is asio. Are there any examples of using non-asio transports in a way that the requests do ultimately get sent over the network?

zaphoyd commented 7 years ago

I (the library author) have bundled three transports with the library. Only one of these (Asio) includes all of the code to do things like dns queries, generate tcp packets, etc. note that the Asio transport can be used with or without boost.

The raw/io_stream transport is designed to allow programs that either work offline (such as unit testing) or manage their own network (such as a preexisting network traffic analysis program that wants to be able to interpret the bytes that it is getting over the wire in other ways.

The stub transport provides a shell that one can used to write a transport using platform specific networking code.

I have worked on other transports using other libraries (raw BSD sockets, libuv, etc) but only on closed source programs that I don't have permission to share. I'd love to have a second full network transport someday, particularly one specifically tailored to a highly threaded Linux server where Asio is decent but not outstanding. For this to happen in the near future I would probably need someone to sponsor its development.

It is possible that other groups that I am not aware of have open source transport examples.

NuclearC commented 7 years ago

@zaphoyd off-topic: Will there be SOCKS proxy support?

ItsShadowCone commented 7 years ago

@zaphoyd how abstract is raw/io_stream or stub?

I've failed to get asio working under the unreal engine so I'm looking for alternatives. There are abstractions like FSocket, but I don't know what exactly had to be implemented.

Do I need to implement sending the initial http request, tcp packets, ssl, all of that?

zaphoyd commented 7 years ago

@Cl1608Ho WebSocket++ will generate application layer framing (HTTP and WebSocket protocols). The transport is responsible for transport layer framing (TCP, TLS).

If your code can create a raw TCP socket then WebSocket++ will supply the bytes to write to it and interpret all bytes read from it.

somayajulas commented 4 years ago

@zaphoyd I have been reading the documentation and examples in your repo to find out whether I can use this library in the server application, where the application is doing the TLS handshake and then the application pass the context handle to this library to just leverage the WebSocket API (such as completing the WebSocket handshake and etc.,)?

zaphoyd commented 4 years ago

@somayajulas as noted earlier, if your code already manages reading the TCP/network connection you can use WebSocket++'s the raw/iostream transport to process the WebSocket API layer. The rough mechanics are that your application creates a connection and then calls a read method to pass any decrypted bytes you get over the wire to WebSocket++. WebSocket++ will interpret the bytes as a WebSocket protocol stream, call handlers, etc and call the write handler you specify with bytes that you then write back to the next layer.

Currently there isn't a transport that accepts an already connected socket and takes over the network I/O directly