HTTP Server with support for WebSocket

A general discussion forum.
Posts: 6
Joined: 26 Jan 2009, 02:32

HTTP Server with support for WebSocket

Postby atascon » 09 Aug 2010, 04:57

I'd like to give this a go and was wondering on peoples opinion on which might be the best to approach take to do this.

Considering that it should still be able to serve and work as the current HTTPServer, I was thinking of doing:
1 - a new type of server based on the current HTTPServer (et al.) sources. This will, most probably, produce duplicated code OR
2 - refactoring the current HTTPServer code to add this a capability of it. Integration and refactoring introducing bugs on what is now clean code OR
3 - Code a specialization of HTTPServerRequest (and HTTPServerRequestFactory of course) that can be used to register a particular URL within the current HTTPServer implementation. It most probably need to take over the management of memory and resources associated with the HTTPSession. Im not sure how much knowledge of the inner workings of HTTPServer it would need. This would then could make the code a potential for bugs if HTTPServer code ever changes in the future (high cohesion).

Consider also that there are socket and thread lifetimes to consider.

On thread lifetime, I'm thinking single thread listening to ALL the current active WebSockets (limit?) making use of a threadpool to then pass processing of incoming messages as opposed to a thread per WebSocket connection model.

On socket lifetime, this has to detach the socket from the HTTPServer somehow and take over the management of it and any associated memory and resources HTTPServer has setup (see point 3 above for potential of creating code with a high cohesion factor).

Any suggestions?


By "give it a go" i obviously mean make the sources available to anyone :)

Reference: ... rotocol-75

Posts: 1268
Joined: 11 Jul 2006, 16:27
Location: Austria

Re: HTTP Server with support for WebSocket

Postby guenter » 09 Aug 2010, 09:09

Hi Alfred,

it would be best to start this off the 1.3.7 (1.4.0) code base. In this release, I have changed the server framework to support "hijacking" (or, in more friendly terms, detaching) the socket underlying a HTTP session. This way, you can use the existing HTTPServer and HTTPRequestHandler machinery to perform the initial WebSocket handshake. After sending the handshake response, the request handler can detach the underlying socket from the HTTP session:

Code: Select all

Poco::Net::StreamSocket socket = static_cast<Poco::Net::HTTPServerRequestImpl&>(request).detachSocket();

You can then do with the socket whatever you'd like. The server's HTTP session will be orderly shut down. A possible approach would be passing the socket to a SocketReactor, which then handles the WebSocket requests. This could be implemented quite easily.

Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 2 guests