Which port should I listen/emit on when using socket.io?
I was originally using 2053 with my SSL website, but found, after using the website in a school, that 2053 had been blocked.
So, is there a particular port I should use that is guaranteed not to be blocked? Or should I assume it could be blocked?
Thanks.
First off, if you're using node.js to serve both your website and your socket.io connections, then you would typically use the same port for socket.io as you use for your web site (whateve port number that is). Since most websites are servered on port 80 (http) or 443 (https), that's what you would use. Since every webSocket connection (which is what socket.io is based on) starts with an http(s) request, they can share a port with your regular web requests and this is a central part of the webSocket design. This also simplifies same origin request security in the browser since no cross origin header support is needed to connect to the same host/port as the web page came from.
For professionally hosted sites, you will probably have to refer to the instructions for using webSocket connections for your particular hosting company. Because webSocket/socket.io connections are long lasting, they often require specific support in a typical hosting environment and may need to be done a particular way. And, because the hosting company may be sharing infrastructure among many sites, you are often assigned specific ports which you can use and are not necessarily free to use just any port.
For your school-end of the connection, ports 80 and 443 will be open as long as the school allows browsing on the internet so those are your safest bets.
FYI, the site http://portquiz.net/ is listening for http requests on all ports so you can test any port you want with it.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments