I am trying to integrate Socket.io with Angular and I\'m having difficulties making a connection from the client-side to the server. I\'ve looked through other related quest
Judging from the messages you send via Socket.IO socket.emit('greet', { hello: 'Hey, Mr.Client!' });
, it seems that you are using the hackathon-starter
boilerplate. If so, the issue might be that express-status-monitor
module is creating its own socket.io instance, as per: https://github.com/RafalWilinski/express-status-monitor#using-module-with-socketio-in-project
You can either:
Pass in your socket.io instance and port as websocket
when you create the expressStatusMonitor
instance like below:
const server = require('http').Server(app);
const io = require('socket.io')(server);
...
app.use(expressStatusMonitor({ websocket: io, port: app.get('port') }));
I think you should define your origins
for client side as bellow:
//server.js
const socket = require('socket.io');
const app = require('express')();
const server = app.listen('port');
const io = socket().attach(server);
io.origins("your_domain:port www.your_domain:port your_IP:port your_domain:*")
io.on('connection', (socket) => {
console.log('connected a new client');
});
//client.js
var socket = io('ws://:port');
In my case, I have just install express-status-monitor to get rid of this error
here are the settings
install express-status-monitor
npm i express-status-monitor --save
const expressStatusMonitor = require('express-status-monitor');
app.use(expressStatusMonitor({
websocket: io,
port: app.get('port')
}));
Edit your nginx web server config file as:
server {
listen 80;
server_name 52.xx.xxx.xx;
location / {
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header Host $http_host;
proxy_pass "http://127.0.0.1:4200";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
}
I solved this by changing transports from 'websocket' to 'polling'
var socket = io.connect('xxx.xxx.xxx.xxx:8000', {
transports: ['polling']
});
After using following load balancer setting my problem solved for wss but for ws problem still exists for specific one ISP.
calssic-load-balancer