Socket.io在ubuntu 16.04上不起作用

时间:2022-05-05 23:41:44

I have a issue about socket.io. This is when i runned the code on my computer (local) i can use the http://IP:120/socket.io/socket.io.js but I am using on the my sever (Digital ocean server ubuntu 16.04) i did not see anything from this url why ? Where is the my fault ? Can anyone help me ? I am used the createServer and Server function but Did not work both of them

我有关于socket.io的问题。这是当我在我的计算机上运行代码(本地)时,我可以使用http:// IP:120 / socket.io / socket.io.js,但我在我的服务器上使用(数字海洋服务器ubuntu 16.04)我从这个url没有看到任何东西为什么?我的错在哪里?谁能帮我 ?我使用的是createServer和Server函数但是没有使用它们

var app = require('express')();
//var http=require('http').Server(app);
var http=require('http').createServer(app);
var io=require('socket.io')(http);
app.get("/",function(req,res){

    res.sendfile(__dirname+"/asd.html");

});


io.on('connection',function(socket) {


    console.log("A User Connected");


});

var port=120;
http.listen(port,'ServerIP');

1 个解决方案

#1


1  

The solution is related to setting up the ports required for the communication.
By default, all ports except :80 are blocked in Digital Ocean

该解决方案与设置通信所需的端口有关。默认情况下,除80以外的所有端口都在Digital Ocean中被阻止

You need to open your port 120 first:

您需要先打开您的端口120:

iptables -I INPUT 1 -i eth0 -p tcp --dport 120 -j ACCEPT

#1


1  

The solution is related to setting up the ports required for the communication.
By default, all ports except :80 are blocked in Digital Ocean

该解决方案与设置通信所需的端口有关。默认情况下,除80以外的所有端口都在Digital Ocean中被阻止

You need to open your port 120 first:

您需要先打开您的端口120:

iptables -I INPUT 1 -i eth0 -p tcp --dport 120 -j ACCEPT