简体   繁体   English

将socket.io客户端连接到其他主机

[英]Connecting socket.io client to different hosting

So a website of mine is hosted on godaddy, now I want to connect it with a server that is running socket.io, and I have some balance on digitalocean. 因此,我的网站托管在godaddy上,现在我想将其与运行socket.io的服务器连接,并且我在digitalocean上拥有一些平衡。 However, I am not sure how I would do this, I think it should be like this for client side? 但是,我不确定该怎么做,我认为对于客户端来说应该是这样吗?

var socket = io.connect('http://Digital.ocean.ip.here:port');

and then server side like this 然后像这样的服务器端

http.listen(port, function(){
  console.log('listening on *:port');
});

the only thing is that if this is how I am supposed to do it (and it even is possible if it's not the localhost), than users will be able to see the ip of my droplet when they take a look in the source code, and perhaps DDOS it or maybe worse I don't know? 唯一的事情是,如果这就是我的工作方式(即使不是本地主机,甚至有可能),那么当用户查看源代码时,用户将能够看到我的drop的ip,也许是DDOS,或者更糟,我不知道? When I see other sites using socket.io for a chat for instance, I never see their IP. 例如,当我看到其他使用socket.io进行聊天的站点时,我再也看不到它们的IP。 Does that mean they host their entire website on a service provider where they are able to use socket.io/node.js? 这是否意味着他们将整个网站托管在可以使用socket.io/node.js的服务提供商上? Any answer will be highly appreciated! 任何答案将不胜感激!

--Edit-- - 编辑 -
My client wouldn't accept http and therefore I decided to buy a domain and ssl so it would use https. 我的客户不接受http,因此我决定购买域和ssl,以便使用https。

There's no way to every hide the IP address of a server that a browser connects to. 没有办法完全隐藏浏览器连接的服务器的IP地址。 It makes no difference whether the connection to the server is http or socket.io or any other TCP based connection. 与服务器的连接是http还是socket.io还是任何其他基于TCP的连接都没有区别。 Anyone can see the IP address. 任何人都可以看到IP地址。 So, that simply isn't something you can protect or should worry about. 因此,这根本不是您可以保护或应该担心的事情。

In most cases, code will use a DNS host name (not an IP address), but the DNS service itself provides a way to lookup the IP address for a host name so the IP address can be fetched that way. 在大多数情况下,代码将使用DNS主机名(而不是IP地址),但是DNS服务本身提供了一种方法来查找主机名的IP地址,以便可以通过这种方式获取IP地址。 Or, one can just load a debugger or local network snooper and easily see what IP address is being connected to. 或者,只需加载调试器或本地网络监听器,即可轻松查看所连接的IP地址。 A host's IP address is simply not a secret. 主机的IP地址根本不是秘密。

If you are worried about DDOS, then you will have to implement server-side protection from those types of attacks. 如果您担心DDOS,则必须实施服务器端保护以防止此类攻击。 You can't do anything in the client to protect from those kinds of attacks. 您无法在客户端中采取任何措施来保护自己免受此类攻击。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM