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
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>
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 commands.
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.
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)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.