默认情况下,socketIO客户端侦听哪个端口? [英] what port does the socketIO client listen to by default?

查看:456
本文介绍了默认情况下,socketIO客户端侦听哪个端口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当您未在客户端的io.connect()函数中指定端口时,客户端会侦听哪个端口?

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

例如:

var socket = io.connect('http://example.com/'); // listening to port 80?

我问的原因是因为我在Heroku上部署了此应用程序的服务器端.前端是一个IOS应用程序.我用于前端的目标C socketIO库( https://github.com/pkyeck /socket.IO-objc )要求我指定端口.但是我不确定应该听哪个端口,因为这在服务器端不是静态的.

The reason I ask is because I deployed the server side of this application on heroku. The front end is an IOS application. The objective C socketIO library I'm using for the front end (https://github.com/pkyeck/socket.IO-objc) requires me to specify a port. But I'm not sure what port I should listen to since this is not static on the server side.

我用javascript编写了用于测试的客户端程序,当我未指定端口时它可以工作.

I wrote client program in javascript for testing and it works when I do not specify a port.

任何帮助将不胜感激.

推荐答案

它在服务器侦听的端口上侦听.假设您将服务器设置为侦听端口8080.然后在http://localhost:8080加载页面,服务器返回包含与套接字相关的JS代码的页面.

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. 如果未在var socket = io.connect();中指定任何端口或主机,则默认为当前页面的主机和端口.
  2. 如果仅指定与当前主机相同的主机,则默认为当前主机的端口.
  3. 如果仅指定与当前主机不同的主机,则如果协议为HTTP,则默认为端口80.如果协议是HTTPS,则端口默认为443.
  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.

这是 url的相关代码. js 解析器.

这篇关于默认情况下,socketIO客户端侦听哪个端口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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