Friday, 22 June 2018

Echoing incoming socket io to TCP connection

Full source below. Getting my feet wet with node.js, have created a simple server that echos any data it receives. I have successfully connected and communicated with several clients via socket.io but now I'm trying to transmit over TCP to a .NET application.I'm missing how to to a socket.write() call inside the io.on function. I'm sure I'm missing the obvious, would appreciate any help.var app = require('express')(); var http = require('http').Server(app); var io = require('socket.io')(http); var net = require('net'); var tcp_server = net.createServer(function(socket) { console.log('TCP Server Created'); }); tcp_server.listen(3600, function(){ console.log('listening on *:3600'); }); http.listen(3500, function(){ console.log('listening on *:3500'); }); io.on('connection', function(socket){ console.log('user connected'); socket.on('update', function(msg){ io.emit('update', msg); //Want to broadcast msg over TCP here console.log('update', msg); }); }); tcp_server.on('connection', function(socket){ console.log('TCP user connected'); socket.on('data', function(msg){ io.emit('update', msg); socket.write(msg); console.log('data', msg); }); });

Submitted June 22, 2018 at 04:10PM by PeanutTheGladiator

No comments:

Post a Comment