简体   繁体   English

我如何获取Websocket的服务器IP地址

[英]How do I get my server Ip address for my websocket

I've created a server using c++ and crow that uses webSockets to communicate with the client (which is an ionic app). 我使用c ++和crow创建了一个服务器,该服务器使用webSocket与客户端(这是一个离子应用程序)进行通信。 I've been do everything through localhost but now I want to deploy the webapp to my iphone and have it communicate with the server. 我已经通过localhost进行了所有操作,但是现在我想将webapp部署到我的iphone并使其与服务器通信。 How do I get the URL for the server for the client to use in it's websocket so it can talk to the server? 如何获取服务器的URL,以供客户端在Websocket中使用,以便它可以与服务器对话?

In most cases when you want to host it for production you would upload it to a hosting provider (eg Azure, AWS, Heroku...). 在大多数情况下,当您要将其托管用于生产时,可以将其上载到托管提供商(例如Azure,AWS,Heroku ...)。

Once you set up a server with the hosting provider they will provide you with the IP address and/or a URL to connect to the hosted service which you can use in your application. 与托管服务提供商设置服务器后,它们将为您提供IP地址和/或URL,以连接到您可以在应用程序中使用的托管服务。

Well, if your server is like webhost,VPS,CLOUD,or dedicated server, it has static ip address which you can use in your client websocket as the address. 好吧,如果您的服务器是webhost,VPS,CLOUD或专用服务器,则它具有静态ip地址,您可以在客户端websocket中将其用作地址。 Also, the better approach is to point a domain name to the ip address of the server (or host) so that your client can always find the server. 另外,更好的方法是将域名指向服务器(或主机)的IP地址,以便您的客户端始终可以找到服务器。

In case you are trying to connect it to your local machine behind a router or modem, then your server might be behind NAT. 如果您尝试将其连接到路由器或调制解调器后面的本地计算机,则您的服务器可能在NAT之后。 Find appropriate port-forwarding configuration for your router and forward incoming and outgoing TCP public ports to your local address. 查找适合您的路由器的端口转发配置,并将传入和传出的TCP公共端口转发到您的本地地址。 then use your public ip address for websocket address ( what is my ip ). 然后使用您的公共IP地址作为websocket地址( 我的IP是什么 )。

Also, in case your public ip address is dynamic and might change over time, there are services like noip.com that help you create a free domain and use it in your client which helps you find the right ip address all the time. 另外,如果您的公共IP地址是动态的,并且可能随时间变化,则有诸如noip.com之类的服务可以帮助您创建一个免费域,并在您的客户端中使用它来帮助您始终找到正确的IP地址。

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

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