-
-
Save kapiltekwani/9b34de51eda3e43e52dcb7ddb5f9d13d to your computer and use it in GitHub Desktop.
client -> socket.io server 1 (clientserver.js) -> socket.io server 2 (serverserver.js)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var app = require('express')() | |
| , server = require('http').createServer(app) | |
| , io = require('socket.io').listen(server); | |
| server.listen(3012); | |
| app.get('/', function (req, res) { | |
| res.sendfile(__dirname + '/index.html'); | |
| }); | |
| var clientio = require('socket.io-client'); | |
| var client = clientio.connect('http://localhost:3013'); | |
| io.sockets.on('connection', function (socket) { | |
| socket.on('client', function(data) { | |
| console.log('clientserver data', data); | |
| client.emit('my event', data); | |
| }); | |
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <!doctype html> | |
| <html> | |
| <head> | |
| <script src="/socket.io/socket.io.js"></script> | |
| <script> | |
| var socket = io.connect(''); | |
| socket.on('connect', function() { | |
| console.log('connect'); | |
| setInterval(function() { | |
| socket.emit('client', { random : Math.random() }); | |
| }, 3000); | |
| }); | |
| </script> | |
| </head> | |
| <body> | |
| </body> | |
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var io = require('socket.io').listen(3013); | |
| io.sockets.on('connection', function (socket) { | |
| console.log('connection'); | |
| socket.on('my event', function (data) { | |
| console.log('serverserver data', data); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment