title: Combining Nodejs Net socket and Socket IO
body: <p>I have a windows application (Built on C# as windows service) that sends data to NodeJs Net Socket, So since Socket.IO helps making a Web Application a live one , without the need of reload. How can i allow Socket.IO stream the received data from NodeJs Net Socket to the Web Application , in the exact moment the Net Socket receives data from C#?</p>
  
  <p>So in the code that receives the socket data from C#:</p>
  
  <pre><code>var net = require('net');
      net.createServer(function (socket) {
          socket.on('data', function (data) {
                  broadcast(socket.name + "&gt; \n" + data + " \n", socket);
                  socket.end("&lt;EOF&gt;");
  
                  //send data to web interface , does it work that way?
                  //SomeFooToSendDataToWebApp(Data)
          });
     });
  </code></pre>
  
  <p>Further more for the Socket.IO i have those lines , which i cant really figure out how to deal with them:</p>
  
  <pre><code>//Should it listen to net socket or web socket?
  server.listen(8080);
  
  // Loading socket.io
  var io = require('socket.io').listen(server);
  
  // It works but only for one request
  io.sockets.on('connection', function (socket2) {
      socket2.emit('message' , 'Message Text');   
  });
  </code></pre>
  
  <p>P.S: I am new to nodejs &amp; socket.io , so if its possible as well to explain their behavior.</p>
  
  <p>Edit 1 : My Front End Javascript to check it if it has any problems:</p>
  
  <pre><code>  //for now it listens to http port , which Socket.IO listens to
    var socket = io.connect('http://localhost:8080');
              var myElement = document.getElementById("news");
              socket.on('message', function(message) {
                  document.getElementById("news").innerHTML  = message;
              })
  </code></pre>
  
  <p>Edit 2 : Did follow jfriend00's answer as it seems my previous code tries were trying to send messages to an unknown socket, i only added this since i needed it to be sent to all the connected clients , so only one line fixed it !</p>
  
  <pre><code> socket.on('data', function (data) {
                  broadcast(socket.name + "&gt; \n" + data + " \n", socket);
                  socket.end("&lt;EOF&gt;");
  
                  //send data to web interface , does it work that way?
                  //The Added code here:
                  io.emit('message',data + " more string");
  
          });
  </code></pre>