This example shows you how to build WebSockets server which acts as a simple proxy for WebSocket traffic and which forwards the message content on a raw TCP connection to another server for processing. This example uses our WebSocket Tools Library
to implement the WebSocket protocol. The basic structure of the server is very similar to the Binary WebSocket Echo Server
example and you should go and read about that first and have a good understanding of how everything fits together. This document will only cover the differences between that example and this one.
This example requires the "WebSockets" licensing option of The Server Framework and it requires libraries that only ship with that option (see here
for licensing options). You can always download the latest version of this example from here
; and although you will need the correct libraries to be able to build it you can look at the example code and see how it works and perhaps get ideas from it. A compiled, unicode release, build of this example is available on request if you require it for performance analysis of the framework.
The main difference in this sever is that we also create normal outbound TCP connections to an external server and that we route the inbound data from the WebSocket client to the external TCP server and then route any data from the TCP server back to the WebSocket client. The example is simple in that it doesn't add any framing to the raw message data that is sent to the destination server and so relies on the messages being self describing and not requiring any additional framing; we can get away with this as the destination server simply echoes all bytes back to us and we then form them into arbitrary WebSocket messages and send them back to the client.