socket problem chat?

Discussion in 'Java' started by Marc Collin, Dec 7, 2005.

  1. Marc Collin

    Marc Collin Guest

    hi

    i would like to know how in a application client/server how we send received
    message to all client?

    thanks
    Marc Collin, Dec 7, 2005
    #1
    1. Advertising

  2. Marc Collin

    Chris Smith Guest

    Marc Collin <> wrote:
    > i would like to know how in a application client/server how we send received
    > message to all client?


    In general, there are two ways. One is to use multicast. The other is
    to individually send the message to each client. Unless you're dealing
    with a very large number of clients, it's probably best to do the
    latter. Just keep a list of clients, and write a list to send messages
    to each one... perhaps each in a different thread to control the delay.

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 7, 2005
    #2
    1. Advertising

  3. Marc Collin

    Roedy Green Guest

    On Tue, 06 Dec 2005 23:17:06 -0500, Marc Collin
    <> wrote, quoted or indirectly quoted someone
    who said :

    >i would like to know how in a application client/server how we send received
    >message to all client?


    Consider using UDP. You can even then have clients send direct to each
    other.

    see http://mindprod.com/jgloss/udp.html
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Dec 7, 2005
    #3
  4. Marc Collin

    Marc Collin Guest

    Chris Smith wrote:

    > Marc Collin <> wrote:
    >> i would like to know how in a application client/server how we send
    >> received message to all client?

    >
    > In general, there are two ways. One is to use multicast. The other is
    > to individually send the message to each client. Unless you're dealing
    > with a very large number of clients, it's probably best to do the
    > latter. Just keep a list of clients, and write a list to send messages
    > to each one... perhaps each in a different thread to control the delay.
    >


    ok for the second method but we need to connect to the client
    the client need to be a server..
    Marc Collin, Dec 7, 2005
    #4
  5. Marc Collin

    Roedy Green Guest

    On Wed, 07 Dec 2005 10:59:13 -0500, Marc Collin
    <> wrote, quoted or indirectly quoted someone
    who said :

    >ok for the second method but we need to connect to the client
    >the client need to be a server..


    Or:
    1. UDP
    2. every client maintains a socket
    3. clients check in with HTTP every "minute" or so to see if there is
    a massage.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
    Roedy Green, Dec 7, 2005
    #5
  6. Marc Collin

    Chris Smith Guest

    Marc Collin <> wrote:
    > ok for the second method but we need to connect to the client
    > the client need to be a server..


    When you establish a TCP connection from a client to the server, that
    connection is two-way. The server can use it to send data to the
    client. That's why java.net.Socket has methods called getInputStream()
    and getOutputStream().

    If your client disconnect, though, then yes they will need a
    ServerSocket to listen for reconnection attempts from the server (and
    this is also problematic because many -- or most? -- clients won't have
    publicly available ports.)

    --
    www.designacourse.com
    The Easiest Way To Train Anyone... Anywhere.

    Chris Smith - Lead Software Developer/Technical Trainer
    MindIQ Corporation
    Chris Smith, Dec 7, 2005
    #6
  7. Marc Collin

    zero Guest

    Chris Smith <> wrote in news:MPG.1e00f21c1bd135c4989c00
    @news.altopia.net:

    > Marc Collin <> wrote:
    >> ok for the second method but we need to connect to the client
    >> the client need to be a server..

    >
    > When you establish a TCP connection from a client to the server, that
    > connection is two-way. The server can use it to send data to the
    > client. That's why java.net.Socket has methods called getInputStream()
    > and getOutputStream().
    >
    > If your client disconnect, though, then yes they will need a
    > ServerSocket to listen for reconnection attempts from the server (and
    > this is also problematic because many -- or most? -- clients won't have
    > publicly available ports.)
    >


    Typically it's the client that connects to the server. The server just
    sits, waiting for clients to connect. If you need the server to connect to
    the client (instead of the other way around) you may want to rethink your
    design.

    --
    Beware the False Authority Syndrome
    zero, Dec 7, 2005
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    0
    Views:
    2,190
  2. Laszlo Nagy
    Replies:
    1
    Views:
    4,808
    Mark Wooding
    Jan 27, 2009
  3. Jean-Paul Calderone
    Replies:
    0
    Views:
    960
    Jean-Paul Calderone
    Jan 27, 2009
  4. Laszlo Nagy
    Replies:
    0
    Views:
    542
    Laszlo Nagy
    Feb 1, 2009
  5. Steve Holden
    Replies:
    0
    Views:
    657
    Steve Holden
    Feb 1, 2009
Loading...

Share This Page