是否可以访问 Web 服务器上的不同端口?

发布于 2024-10-12 17:44:47 字数 324 浏览 5 评论 0原文

我创建了一个游戏,我想将其放到网上。我想购买一个网站(我可能会使用 goddaddy 购买域名并将其用作网络主机)作为处理游戏的服务器。因为每个游戏都需要一个单独的服务器,所以我需要每个游戏的服务器存在于不同的端口上。所以这引出了我的问题,是否可以在我未来的网络服务器上访问这些端口? (我用 Java 编写了该程序,因此我假设我将通过为 ServerSocket 选择端口来从服务器端访问端口,并通过使用网站的 IP 地址和为 Socket 选择的端口从客户端访问端口)

(注意:另外,我知道简单地使用一个端口并在不同的线程上运行服务器可能更容易,但我只是想知道我的问题得到解答)

非常感谢, 伊恩

I created a game and I want to put it on online. I want to buy a website (I'll probably use goddaddy to buy a domain name and use them as the web host) to use as the server to handle game play. Because I would need a separate server for each game, I would need each game's server to exists on different ports. So this leads to my question, is is possible to access these ports on my future web server? (I wrote the program in Java, so I would assume that I would access the ports from the server side by choosing a port for a ServerSocket, and from the client side by using the IP address from the website and the chosen port for a Socket)

(note: also, I am aware that it may be easier to simply use one port and run the servers on different threads instead, but I am just curious to have my question answered)

thanks a lot,
Ian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

摇划花蜜的午后 2024-10-19 17:44:47

从技术上讲,可以使用不同的端口,但我不认为像 goddaddy 这样的网络托管商会让您运行绑定到特殊端口的 java 进程。

Technically it is possible to use different ports, but I don't think that a webhoster like goddaddy will let you run a java process that binds to a special port.

债姬 2024-10-19 17:44:47

如果您的意思是要创建自己的 TCP 服务器,那么显然您可以创建尽可能多的服务器实例并将它们配置为侦听不同的端口。但现在已经是2011年了。这个解决方案在 90 年代初还不错。

我建议您使用通过 HTTP 运行的 Restful API。在这种情况下,您可以使用 URL 将调用转发到每个应用程序的服务器端,例如

http://www.lan.com/foo/login?user=u123&password=123456 - 登录应用程序 foo

http://www.lan.com/bar/login?user=u123&password=123456 - 登录到应用程序栏

在这种情况下,您需要只有一台服务器(Web 服务器)正在侦听套接字(端口 80)。
您的服务器端实现可以根据您的选择使用各种 Web 技术(php、java、asp.net 等)来完成。

If you mean that you are going to create your own TCP server you obviously can create as many instances of your server and configure them to listen to different ports. But it is year 2011 now. This solution was OK in early 90s.

I'd suggest you to use Restful API that works over HTTP. In this case you can forward calls to server side of each application using URL, e.g.

http://www.lan.com/foo/login?user=u123&password=123456 - log in into application foo

http://www.lan.com/bar/login?user=u123&password=123456 - log in into application bar

In this case you need only one server (the web server) that is listening to socket (port 80).
Your server side implementation could be done using various web techonlogis (php, java, asp.net etc) on your choice.

山色无中 2024-10-19 17:44:47

是的,那应该有效。安全管理器允许连接到加载小程序的同一 IP 地址上的不同端口。

Yes, that should work. The security manager permits connections to a different port on the same IP address that the applet was loaded from.

蓝天白云 2024-10-19 17:44:47

您可以在任何您想要的端口上运行 Java 服务器。每台服务器将在一个端口上接受传入请求。

正确的方法是简单地在一个端口上运行,每个连接将实例化一个新的 servlet 实例(恰好在它自己的线程中运行),然后该实例可以为该请求提供服务。您通常不需要运行单独的端口或担心​​并发性,特别是如果连接之间共享的所有内容(例如一个游戏中的多个玩家)都是通过数据库读/写处理的。

您的主机 (GoDaddy) 必须允许您使用这些端口,但如果他们提供适当的托管(而不是虚拟托管)并为您提供自己的 IP,那么您没有理由不能这样做。

You can run a Java server on whatever port you want. Each server will accept incoming requests on one port.

The correct way is simply run on one port and each connection will instantiate a new servlet instance (which happens to run in its own thread) that can then service that request. You usually don't need to run separate ports or worry about concurrency, especially if all the stuff that's shared between connections (e.g. multiple players in one game) is handled through database read/writes.

Your host (GoDaddy) will have to allow you use of those ports, but if they are providing proper hosting (not virtual hosting) and given you your own IP there's no reason why you shouldn't be able to.

那伤。 2024-10-19 17:44:47

你的解决方案理论上可能有效,我喜欢 AlexR 的解决方案。但是像 godaddy 这样的提供商不允许您在任何端口上运行 java 服务器。您需要找到这样做的人。我发现成本从 5 美元/月上升到大约 20 美元/月,但你得到了一台更好(读取速度更快)的机器。良好的祝愿,-女士。

Your solution may work theoritically, and I like AlexR's solution. But providers like godaddy doesnt let you run a java server, on ANY port. You will need to find out somebody who does. What I found is the cost goes up from $5/mo to about $20/mo, but you get a much better (read faster) machine. Good wishes, - MS.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文