I am trying to connect two node.js servers using socket.io and socket.io-client. In both cases, I am using v0.9.16.
In my case, I call the servers the STREAM SERVER and the ACTIVITY SERVER where the activity server uses the socket.io-client module.
STREAM SERVER - (THE CODE ON THE SERVER THAT ACTS LIKE A SERVER)
var https = require('https');
var express = require('express');
var socket = require('socket.io');
var securePort = (process.env.LOCAL_HTTPS_PORT || 443);
var sslOptions = //CERTIFICATE
var socketIoConfiguration = //CONFIG VALUES
var app = express();
var server = https.createServer(sslOptions, app);
var io = socket.listen(server, socketIoConfiguration('activityToStream'));
io.sockets.on('connection', function (socket) {
console.log('Activity server connected to stream server.');
});
server.listen(securePort);
ACTIVITY SERVER - (THE CODE ON THE SERVER THAT ACTS LIKE THE CLIENT)
var socketClientModule = require('socket.io-client');
var streamConnectionServer = 'https://165.225.144.273:443';
var activityToStreamSocket = socketClientModule.connect(streamConnectionServer);
activityToStreamSocket.on('connect', function(socket){
console.log('Connected to Stream Server');
});
When I run this code, I don't get any message from either server. However, when I run this code from an HTML page served in Chrome, I see messages on the output of the Stream server:
<!DOCTYPE html>
<html>
<head>
<title>
Test
</title>
<script src="https://165.225.144.273/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('https://165.225.144.273');
socket.on('news', function (data) {
console.log(data);
socket.emit('my other event', { my: 'data' });
});
</script>
</head>
<body>
Hello World
</body>
</html>
STREAM SERVER MESSAGES WHEN CLIENT RUN IN CHROME
debug: client authorized
info: handshake authorized UaUDRsA3ZBTgdsiLDCrl
debug: setting request GET /socket.io/1/websocket/UaUDRsA3ZBTgdsiLDCrl
debug: set heartbeat interval for client UaUDRsA3ZBTgdsiLDCrl
debug: client authorized for
debug: websocket writing 1::
So, it makes me think the issue is with my "ACTIVITY SERVER" running socket.io-client, but I cannot figure out why its not working at all (no error messages, etc.)
Use the same version of socket server and client
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With