简体   繁体   中英

Connecting clients directly after they connect to a central server

I have a program where I want 4 clients to each connect to a central server, and once all 4 clients connect, the server sends the information of each other client to each client, so the central server "steps out of the way" and each of the clients can directly connect to the other 3 clients. I've tried writing the Socket object of the clients but I realized that kind of nonsensical and Sockets are not serializable anyway. What's the best technique for doing this?

Clients (which are also servers) need to document the ip and port they each will listen to, as some string & int, or InetAddress & int, or SocketAddress. It has nothing to do with the connection they just made to the rendez-vous server, (although the remote client IP the server sees might be the same, but not the port).

This is your protocol to invent (serialization or dataoutputstream or else, have fun). Then any client has the ip/port to open sockets to all others.

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