0
votes

I have a network consists of 5 machines. One machine called leader (server), other called followers (clients). I use ServerSocket in leader side (to make it server) and use Socket in follower side to make them clients. This structure works perfectly.

Now, I want to add new change to above network. I would like to allow follower (clients) to send a message to others followers. How can I achieve that?

Is it possible to achieve that by making each follower (client) has Socket (connect with leader) and ServerSocket (connect to followers)?.

I look forward to hearing from you.

2
I did not mean how to run the clent and the server in one machine. What I meant is that how to make client act as client as well as server.user3298986

2 Answers

1
votes

Leader can have the list of followers(Each follower can have an unique id). If a follower needs to pass message to another follower, he needs to pass the data to the Leader, and leader in turn can publish it to the intended follower or the leader can broadcast it to all followers. Leader can run different threads for each connection it has received and maintain a client pool for broadcasting.

0
votes
Can one machine act as client and server at same time using socket in Java?

Socket = IP + port. As long as both sockets on same machine(localhost) have different ports it is possible.