A simple TCP-based echo server
Since the WebSocket client API itself is not enough (to build a “real” application), we need some (existing) backend, or server. A very simple example would be to bring a (TCP) echo server to the browser, via WebSocket:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write("Echo server\r\n");
socket.pipe(socket);
});
server.listen(1337, "127.0.0.1");
The above code is a VERY simple “EchoServer” that runs on port “1337″. It is in Node.js. The code is borrowed from their website.
Bring it to the Web
To be able to access this TCP server with a WebSocket application you need to add the following configuration to the Kaazing WebSocket Gateway:
<service>
<accept>ws://localhost:8000/echo</accept>
<connect>tcp://localhost:1337/</connect>
<type>proxy</type>
<cross-site-constraint>
<allow-origin>*</allow-origin>
</cross-site-constraint>
</service>
Read more: Matthias Wessendorf's Weblog
QR: