最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ubuntu openunblock ports for nodejs - Stack Overflow

programmeradmin6浏览0评论

I'm trying to listen port 8080 for socket.io but I get error:

http://localhost:8080/socket.io/?EIO=3&transport=polling&t=Lai1FQh net::ERR_CONNECTION_REFUSED

I'm using ubuntu virtual machine from digitalocean and first when I ssh login I get message:
The "ufw" firewall is enabled. All ports except for 22, 80, and 443 are BLOCKED.

I'm beginner with this but doesn't that mean that port 8080 is blocked.
How do I fix this and what I need to do

Here is my code for server:

var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );

var app = express();
var server = http.createServer( app );

var io = socket.listen( server );

server.listen(8080, function(){
    console.log("Listening");
})

In my website i just connect to that port like this:

<script src="node_modules/socket.io-client/dist/socket.io.js"></script>
<script>
    var socket = io.connect( 'http://localhost:8080' );
    ...
<script>

I'm trying to listen port 8080 for socket.io but I get error:

http://localhost:8080/socket.io/?EIO=3&transport=polling&t=Lai1FQh net::ERR_CONNECTION_REFUSED

I'm using ubuntu virtual machine from digitalocean and first when I ssh login I get message:
The "ufw" firewall is enabled. All ports except for 22, 80, and 443 are BLOCKED.

I'm beginner with this but doesn't that mean that port 8080 is blocked.
How do I fix this and what I need to do

Here is my code for server:

var socket = require( 'socket.io' );
var express = require( 'express' );
var http = require( 'http' );

var app = express();
var server = http.createServer( app );

var io = socket.listen( server );

server.listen(8080, function(){
    console.log("Listening");
})

In my website i just connect to that port like this:

<script src="node_modules/socket.io-client/dist/socket.io.js"></script>
<script>
    var socket = io.connect( 'http://localhost:8080' );
    ...
<script>
Share Improve this question edited Dec 23, 2016 at 14:35 Tonza asked Dec 23, 2016 at 14:17 TonzaTonza 6501 gold badge9 silver badges17 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

The error message you get means that ufw (it's a firewall) is blocking all ports except those 3.

To enable port 8080:

sudo ufw allow 8080

Then reboot your server.

(As seen from the guide available on your hosting provider website)

You probably have another instance of your program running, or some other program that uses that port. Run:

ps aux

in your shell to see what processes are running and kill those that shouldn't be running. You can also run lsof or netstat to see what is listening on which port. See the manuals for those mands.

If you can open 8081 or something like that but not 8080 then it means that something is already listening on port 8080. You can verify it with trying to connect to that port with curl, wget, netcat or by using nmap. See their man pages for details.

发布评论

评论列表(0)

  1. 暂无评论