简体   繁体   中英

Java - How to simulate one server with multiple clients that communicate through that server?

I am developing a little Java chat application that will run reliably on a small local area network.
I have Windows 7 installed in my machine (laptop).
I developed a server and a client that will represent (chat Messenger)

If the server runs, then any client can run and communicate with the server.
In the machine that runs the server, it can also run one client (client_1) to communicate with the server in the same machine.
If I want to run a second client (client_2) to communicate with client_1 through the server. Then I have to run it (client_2) in a another machine.

Is there a away to simulate two machines or two real clients that communicate with the server while using the same machine?

Addendum:
I only need this in the development stage. I just want to be able to develop and test in the same machine. But the final product will run as supposed to be, that is each client will run on a single machine. It is not a programming logic problem.

The simplest solution I can think: clients should open socket to the server with "localhost" as inet address. Then you can run multiple instance of them.

new Socket("localhost", port);

考虑使用VMWare,因为您可以在单个“逻辑”计算机网络中配置多个系统和虚拟IP。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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