Results 1 to 4 of 4

Thread: Messenger (Client/Server)

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    13

    Messenger (Client/Server)

    Hi,
    i do not have pretty much experience in Java....and needs to create a messenger where client can send/receive messages. i created server and client...multiple client can connect to server and can pass messages too but , i dont know how to send those messages to client rather then sending to server....

    How and where can i display the connected clients on form (do i need to create separate class ...)?

    Can i run run the server through a button..if yes then in action code what do i need to write ...either class name ....or what..?

    Please help me

  2. #2
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Messenger (Client/Server)

    you have to broadcast each message recieved to the other clients(except the sender).

    The server is the middle man, so you'll have to send it to the server, then the server sends to the other clients.

    and if you are doing it correctly, everytime the server recieves a connection, you throw that connection into another thread so the server can recieve multiple connections, and deal with them in a parallel state.

    now everytime the server gets a message from that client, "serverInputStream" you just send that to all the clients. ( each socket has an inputstream and outputStream)

    which each client should have an outputStream and you just write that text to all the other clients outputstream and each client has its own inputStream on the client-side as well, and you just have a thread listening for the client to recieve something on its inputStream.

    Justin Fox
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2008
    Posts
    13

    Re: Messenger (Client/Server)

    Now i m able to send back that client message to server and then server sent back that message to client......i can connect multiple clients...but when i sent message to server,,,they are getting there individual message back ....so it mean that server not boardcasting message...so in this case what should next step...and how server identify the client...?

    REgards

    Quote Originally Posted by MonkOFox
    you have to broadcast each message recieved to the other clients(except the sender).

    The server is the middle man, so you'll have to send it to the server, then the server sends to the other clients.

    and if you are doing it correctly, everytime the server recieves a connection, you throw that connection into another thread so the server can recieve multiple connections, and deal with them in a parallel state.

    now everytime the server gets a message from that client, "serverInputStream" you just send that to all the clients. ( each socket has an inputstream and outputStream)

    which each client should have an outputStream and you just write that text to all the other clients outputstream and each client has its own inputStream on the client-side as well, and you just have a thread listening for the client to recieve something on its inputStream.

    Justin Fox

  4. #4
    Frenzied Member
    Join Date
    Feb 2008
    Location
    Texas
    Posts
    1,288

    Re: Messenger (Client/Server)

    well if you can except multiple connections on the server, create a client class that takes that unique connection and stores it.

    and as you create the client objects as they connect, add them to a <Client>ArrayList.

    so when a client sends a message, you broadcast that message to every other client in the arraylist except the one that sent it.

    So you will have an inner class calls 'Client'.

    And a server scope Arraylist for storing those client object;

    Justin Fox
    You down with OOP? Yeah you know me!
    MCAD and MCMICKEYMOUSE (vb.net)

    ----

    If it even kinda helps... rate it : )

    Edit a Multi-page .tif file and save.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width