socket problem chat?

M

Marc Collin

hi

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

thanks
 
C

Chris Smith

Marc Collin said:
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
 
M

Marc Collin

Chris said:
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..
 
R

Roedy Green

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.
 
C

Chris Smith

Marc Collin said:
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
 
Z

zero

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,534
Members
45,008
Latest member
Rahul737

Latest Threads

Top