简体   繁体   English

同一IP上的多个服务器

[英]Multiple Servers on the same ip

I want to know if it is possible to have multiple sockets for servers on the same ip and different ports, and if it is not possible why. 我想知道是否可以在相同ip和不同端口上为服务器提供多个套接字,以及是否不可能。

For Example: 例如:

public static void main (String[]args){
    int nrServers = 2;

    for(int i=0;i<nrServers;i++){
            new Socket("127.0.0.1",5000+i);
    }
}

Thanks. 谢谢。

If by "server" you mean "server process" (or even just a single process listening on several ports), yes, that's not just possible, it's common. 如果用“服务器”来表示“服务器进程”(或者甚至是一个监听多个端口的单个进程),是的,这不仅是可能的,而且很常见。 Nearly all computers (frequently even ones that aren't "servers") do it. 几乎所有计算机(甚至甚至不是“服务器”的计算机)都可以这样做。 Your code is a start toward doing it (you might want to use ServerSocket rather than Socket , and of course you want to actually do something with them, but...). 您的代码是开始这样做的开始(您可能想使用ServerSocket而不是Socket ,当然,您实际上想对它们做点什么,但是...)。

For example, a dedicated server in a data center might well be listening on port 22 (SSH), port 80 (HTTP), port 443 (HTTPS), and possibly others. 例如,数据中心中的专用服务器可能正在侦听端口22(SSH),端口80(HTTP),端口443(HTTPS)以及其他端口。

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

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