what port does the socketIO client listen to by default?

前端 未结 1 905
野的像风
野的像风 2021-02-05 18:37

When you do not specify a port in the io.connect() function on the client side, what port does the client listen to?

eg:

var socket = io.connect(\'http:/         


        
相关标签:
1条回答
  • 2021-02-05 19:05

    It listens on the port the server listens to. Imagine you set your server to listen port 8080. Then you load your page at http://localhost:8080 and the server returns the page which contains the socket related JS code.

    1. If you don't specify any port or host as in var socket = io.connect();, it defaults to the host and port of the current page.
    2. If you specify only the host which is same as the current host, it defaults to the port of the current host.
    3. If you specify only the host which is different from the current host, it defaults to port 80 if the protocol is HTTP. If the protocol is HTTPS, then the port defaults to 443.

    Here is the related code for url.js parser.

    0 讨论(0)
提交回复
热议问题