KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
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: If I send a string constant to an established socket when something is entered in the console it works ok. 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. If I send a local string (instead of the one received from the other scope) it's sent correctly. (commented line: client.send(message) ) 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: // Sample based on: http://elegantcode.com/2011/05/04/taking-baby-steps-with-node-js-websockets/ // Changed for sockets.io 6.x => 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(mess
Tags (comma-separated)
Save Edits
Cancel