I want to make a tcp connection to my server. But i get en error everytime...
WebSocket connection to 'ws://my.ip:1337/' failed: Error during WebSocket handshake: No response code found in status line: Echo server
Client:
var connection = new WebSocket('ws://my.ip:1337');
connection.onopen = function () {
connection.send('Ping'); // Send the message 'Ping' to the server
};
Server:
var net = require('net');
var server = net.createServer(function (socket) {
socket.write('Echo server\r\n');
socket.pipe(socket);
console.log('request');
});
server.listen(1337, 'my.ip');
Whats wrong ?
Solution 1Check that all the Bot Insight services are running. Check that your firewall settings are configured to accept incoming websocket data. Try to use a different web browser. Restart the Bot Insight Visualization and Bot Insight Scheduler services.
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent for example).
WebSockets - Overview In computer science, handshaking is a process that ensures the server is in sync with its clients. Handshaking is the basic concept of Web Socket protocol. The following diagram shows the server handshake with various clients −
Confirm that you're using a supported browser. If not, try using one of those and then check that WebSocket is working (see above). Proxy servers and firewalls. Check if you have a proxy server or firewall that blocks WebSocket access (you might need your system administrator's help).
net.createServer
creates a plain TCP server, not a websocket server. Websockets use a specific protocol over TCP, which a plain TCP server does not follow. The browser successfully makes a network-level connect over TCP, but it then expects a websocket handshake to immediately follow, which the plain TCP server does not know how to provide.
To have your Node.js server listen for websocket connections, use the ws
module:
var WebSocketServer = require('ws').Server
, wss = new WebSocketServer({port: 1337});
wss.on('connection', function(ws) {
ws.on('message', function(message) {
ws.send('this is an echo response; you just said: ' + message);
});
ws.send('send this message on connect');
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With