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 2 of 2

Thread: Multiple clients and one server. How to send data from one client to the others

  1. #1
    Member
    Join Date
    Apr 2011
    Posts
    32
    Thanks
    20
    Thanked 0 Times in 0 Posts

    Default Multiple clients and one server. How to send data from one client to the others

    Hey everyone, I am currently working on a MultiServer class which creates looks for new connections from any client class and creates a thread so that each client can run at the "same time". The client sends data to the server and the server just echos back to that client that sent the data; and does this for all the other clients.

    I am writing this post because my main goal is to have a different functionality rather than the 'echo' nature described above. I would like to have any one client to send data to the server and for the server to send the data to all the other clients connected. My first idea was to have a linked list for the server so that every time a new connection occurs, the linked list grows. My first problem that I noticed was when I thought of the following example:

    Say there were three clients and client 2 sent data. I could 'walk down' the list until I get to the data field that sent the data and then send to client 3 by moving the pointer. How would I send the data to client 1?

    Im sure the above paragraph didnt make sense and am hoping that someone could guide me on how I could send text from one client to other clients.

    NB: I do not require any code, all i am asking is someone to help explain how to do my above question!


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Multiple clients and one server. How to send data from one client to the others

    If there is a list of all the clients, when the server gets a message if could go through the list and send the message to all the clients in the list.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Java TCP multiple clients
    By amjoseph in forum What's Wrong With My Code?
    Replies: 6
    Last Post: April 28th, 2012, 04:39 PM
  2. 1 Server- Multiple Clients Program
    By jclark1186 in forum Java Networking
    Replies: 2
    Last Post: September 23rd, 2011, 11:44 AM
  3. Replies: 1
    Last Post: August 12th, 2011, 10:09 AM
  4. [SOLVED] Server Client does not send file
    By Kakashi in forum What's Wrong With My Code?
    Replies: 0
    Last Post: March 10th, 2011, 12:38 PM
  5. Transmitting from server to all clients.
    By newbie in forum Java Networking
    Replies: 0
    Last Post: December 19th, 2010, 05:07 PM