title: Send data from websocket to socket.io
body: <p><br></p>
  
  <p>I used websocket interface to connect to websocket server . what if i want send data that i receive from the websocket server through my websocket interface to client connected to me through http server , should i use socket.io ? <br></p>
  
  <p><a href="https://i.stack.imgur.com/UDyV6.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/UDyV6.png" alt="enter image description here"></a></p>
  
  <p>so at the end i will have socket.io attached to to http server and websocket interface to get data and in case of message come will be send to client through socket.io . is that the best setup ? </p>
  
  <p><strong>Code Example :</strong> </p>
  
  <pre><code>// Require HTTP module (to start server) and Socket.IO
  var http = require('http'),
      io = require('socket.io');
  var WebSocket = require('ws');
  
  
  var ws = new WebSocket('ws://localhost:5000');
  
  // Start the server at port 8080
  var server = http.createServer(function (req, res) {
  
      // Send HTML headers and message
      res.writeHead(200, {
          'Content-Type': 'text/html'
      });
      res.end('&lt;h1&gt;Hello Socket Lover!&lt;/h1&gt;');
  });
  server.listen(8080);
  
  // Create a Socket.IO instance, passing it our server
  var socket = io.listen(server);
  
  ws.on('open', function open() {
      ws.send('something');
  });
  
  ws.on('message', function (data, flags) {
      // here the data will be send to socket.io
  });
  
  // Add a connect listener
  socket.on('connection', function (client) {
  
      // Success!  Now listen to messages to be received
      client.on('message', function (event) {
          console.log('Received message from client!', event);
      });
      client.on('disconnect', function () {
          clearInterval(interval);
          console.log('Server has disconnected');
      });
  
  });
  </code></pre>