Note that there are some explanatory texts on larger screens.

plurals
  1. POSocket.IO issue with control chars
    primarykey
    data
    text
    <p>I am implementing an application that uses websockets and a console accessed via Telnet. There is a communication between the connection established via websockets and the console. I am experiencing a weird issue:</p> <ul> <li>If I send a string constant to an established socket when something is entered in the console it works ok.</li> <li>If I send a string received from the console scope It seems to open a new socket (not sure) because in the debug log I see it and in the browser side (websockets) it alerts me of a new connection.</li> <li>If I send a local string (instead of the one received from the other scope) it's sent correctly. (commented line: client.send(message) )</li> </ul> <p>I share here the nodeJS code, take into account that this is now a test app so it's assumed only one socket and websockets connection:</p> <pre><code>// Sample based on: http://elegantcode.com/2011/05/04/taking-baby-steps-with-node-js-websockets/ // Changed for sockets.io 6.x =&gt; 7.x var events = require('events'); var eventEmitter = new events.EventEmitter(); var http = require('http'); var socketIO = require('socket.io'); var static = require('node-static'); var port = 2000; var clientFiles = new static.Server('./client'); var httpServer = http.createServer( function(request, response) { request.addListener('end', function() { clientFiles.serve(request, response); }); }) httpServer.listen(port); console.log("Server running at port: " + port); var io = require('socket.io').listen(httpServer); var webSocket = io.sockets; webSocket.on('connection', function(client) { client.send('Please enter a user name ...'); var userName; eventEmitter.on('someOccurence', function(message) { console.log("Received: " + message); client.send('Line Received'); var s = 'popo'; client.send(s); //client.send(message); }); client.on('message', function(message) { console.log(message); if(!userName) { userName = message; client.broadcast.send(message + ' has entered the zone.'); return; } var broadcastMessage = userName + ': ' + message; client.broadcast.send(broadcastMessage); client.send("Repeated here: " + message); }); client.on('disconnect', function() { var broadcastMessage = userName + ' has left the zone.'; client.broadcast.send(broadcastMessage); }); }); var lines = require('lines-adapter'); var net = require('net'); var server = net.createServer(function (socket) { socket.write("Welcome to the Server\r\n"); lines(socket, 'utf8') .on("data", function(line) { console.log("Line received: " + line); eventEmitter.emit('someOccurence', line); } ) .end("end", function() { console.log("End of Stream"); } ); }); server.listen(1337, "127.0.0.1"); </code></pre> <hr> <p><strong>UPDATE:</strong> I just tested with socket.io 0.8.6 and nodeJS 0.4.12 without this issue. I will keep this question here for future reference. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload