Socket.io 在 ubuntu 16.04 上不起作用 [英] Socket.io does not work on the ubuntu 16.04

查看:53
本文介绍了Socket.io 在 ubuntu 16.04 上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 socket.io 的问题.当我在我的计算机(本地)上运行我的代码时,我可以使用 http://IP:120/socket.io/socket.io.js.但是,在我的服务器(数字海洋服务器 ubuntu 16.04)上,我在此 url 上没有看到任何内容.我的错误在哪里?谁能帮我?我使用了 createServer 和 Server 函数,但它们都不起作用.

I have an issue with socket.io. When I run my code on my computer (local) I can use http://IP:120/socket.io/socket.io.js. However, on my server (Digital ocean server ubuntu 16.04) I did not see anything at this url. Where is my error? Can anyone help me? I used the createServer and Server function, but neither of them worked.

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');

推荐答案

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

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

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

You need to open your port 120 first:

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

这篇关于Socket.io 在 ubuntu 16.04 上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆