Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 7 of 7

Thread: Client broadcast message to all clients????

  1. #1
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Client broadcast message to all clients????

    Dear brothers,

    I have this scanario:

    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. As soon as follower receives a meassge from Leader, the follower broadcast the message to all other followers. On other words, I would like to allow follower (clients) to send a message to others followers. How can I achieve that?

    I am able to acheive this by using DatagramSocket (UDP), but DatagramSocket has drawback which it is possible that the message is lost, also the message does not order.

    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. #2
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Client broadcast message to all clients????

    Welcome to the forum! Please read this topic to learn how to post code in code or highlight tags and other useful info for new members.

  3. #3
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Client broadcast message to all clients????

    Usually in a client server architecture only the server sends messages to the clients.
    You could simply send a message to the server and ask the server to forward it to all other clients.
    Otherwise you might make every machine a server and have everybody connect to everybody else. This would, on the other hand, need many more ports and possibly be much less efficient depending on your implementation.

  4. #4
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Client broadcast message to all clients????

    Quote Originally Posted by Cornix View Post
    Usually in a client server architecture only the server sends messages to the clients.
    You could simply send a message to the server and ask the server to forward it to all other clients.
    Otherwise you might make every machine a server and have everybody connect to everybody else. This would, on the other hand, need many more ports and possibly be much less efficient depending on your implementation.
    Thank you very much, the main aim of my implementation is to reduce the load on leader. So as soon as the leader sends a proposal message to followers, I need each follower to send ACK (Acknonwlegment) to all followers including the leader (ACK means agreement upon the proposal). In this case, each follower will commits the proposal, no need to wait for commit from the leader.

    This communcation usually in state-machine replication protocol. The protocol cosists of three phases to manage execution of update requests. Phase 1 leader sends proposal (update request) to all followers. phase 2 when followers receive proposal they send ACK (means agree on change) to leader. phase 3 as soon as leader receice the majority of ACK from the followers, leader sends commit message to followers to deliver the update requests (means to apply the repuset in thier memory of disk).

    So in this scanario leader get much of work, therfore I need to reduce to load on leader and distribute among the followers. I come up with different designs. But now I need to make the follower (client) be able to send and receive ACK from other followers.

    I hope it is clear. Any idea to make follower able to send and receive a mesage from other followers?

    Thank you alot.

  5. #5
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Client broadcast message to all clients????

    Sounds like what you want is a peer-to-peer network where each machine in the network has the same rights and possibilities.
    You could implement this with a ServerSocket in each machine, but there might be much better solutions. I have never done this in java.
    Maybe you can find a third party library for this somewhere on the web.

  6. #6
    Junior Member
    Join Date
    May 2014
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Client broadcast message to all clients????

    Quote Originally Posted by Cornix View Post
    Sounds like what you want is a peer-to-peer network where each machine in the network has the same rights and possibilities.
    You could implement this with a ServerSocket in each machine, but there might be much better solutions. I have never done this in java.
    Maybe you can find a third party library for this somewhere on the web.
    Thank uoi sir.

  7. #7
    Junior Member
    Join Date
    Feb 2014
    Location
    Finland
    Posts
    25
    My Mood
    Bored
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Client broadcast message to all clients????

    Quote Originally Posted by Ibrahim View Post
    Thank you very much, the main aim of my implementation is to reduce the load on leader. So as soon as the leader sends a proposal message to followers, I need each follower to send ACK (Acknonwlegment) to all followers including the leader (ACK means agreement upon the proposal). In this case, each follower will commits the proposal, no need to wait for commit from the leader.

    This communcation usually in state-machine replication protocol. The protocol cosists of three phases to manage execution of update requests. Phase 1 leader sends proposal (update request) to all followers. phase 2 when followers receive proposal they send ACK (means agree on change) to leader. phase 3 as soon as leader receice the majority of ACK from the followers, leader sends commit message to followers to deliver the update requests (means to apply the repuset in thier memory of disk).

    So in this scanario leader get much of work, therfore I need to reduce to load on leader and distribute among the followers. I come up with different designs. But now I need to make the follower (client) be able to send and receive ACK from other followers.

    I hope it is clear. Any idea to make follower able to send and receive a mesage from other followers?

    Thank you alot.
    You could investigate different network schemes and find a suitable design for your layout. For example round robin -type so that way you could organize the network of machines not to have connection from each peer to each peer but one peer to one other and so on.

    For example:
    Lets say your clients are A, B, C and D.
    If you want full p2p A would have to serve B, C and D. B would have to serve A, C and D and so on.

    But if you round robin it so that A serves B, B serves C and C serves D you'd only need to "ack" A to start the chain. You'll save alot of connections for a tiny price of latency.

    There might be other even more suitable network architectures depending on size and possible timing issues of the network. As for java side, i believe you will have to use the serversocket-socket structure for TCP/IP connection if the UDP isn't reliable for your needs. But you could implement some kind of light handshake protocol ( send ack -> wait for ack to ack -> if not recieved send another ack etc.. ) to strenghten the reliability of UDP.


    Edit: You might want to look in to this as well: http://docs.oracle.com/javase/tutori...adcasting.html


    Anyway, good luck to your project
    Last edited by Wizand; June 8th, 2014 at 11:33 AM. Reason: Additional info to the post

Similar Threads

  1. Replies: 15
    Last Post: May 9th, 2014, 12:00 PM
  2. Replies: 0
    Last Post: May 8th, 2014, 02:38 PM
  3. Replies: 0
    Last Post: May 31st, 2012, 05:35 PM
  4. Multiple clients and one server. How to send data from one client to the others
    By u-will-neva-no in forum Java Theory & Questions
    Replies: 1
    Last Post: March 21st, 2012, 07:29 PM
  5. Streaming Raw Data to a Client - huge message loss
    By MarkusTandy in forum Java Networking
    Replies: 0
    Last Post: February 19th, 2011, 07:41 PM

Tags for this Thread