Socket programming

J

Justin Creasy

If this is the wrong group for this posting please let me know and I'll
move it.

I have an application that has an ArrayList of sockets to clients. For
standard one-to-one messages my application works great, the problem is
if I want to "broadcast" a message to all my clients. Right now I just
iterate through my sockets list and send the message to each client.
This works fine until I need to send something large like a file. Is
there a way that I can either send a byte stream to multiple sockets at
the same time, or have a socket that each client has a connection to?

If there is such a structure, does it actually broadcast, or does it
iterate through the clients and just make it look like it's
broadcasting. When I used to do MPI programming broadcasting was
faster, but only a little bit faster than iterating through, so I'm not
sure if .NET would be the same.

Anyways, thanks in advance, and if there's a better group for this
question please let me know.
 
N

Nicholas Paldino [.NET/C# MVP]

Justin,

If you are using a TCP/IP socket (as opposed to a UDP socket), then yes,
you will have to iterate through all of your clients.

I believe that if you use a UDP socket, then you can broadcast your
message, and you only have to do it to the one connection, since that is all
you will ever have (since it will be a broadcast socket).

However, using UDP might not be a good idea for you, since it isn't
guaranteed (like TCP/IP) to send the packets. Packets can be dropped, and
when using UDP, that's ok. It's up to you to handle these situations
gracefully.

You might want to just use different threads to write the details to
different sockets. It would prevent you from having to write the files to
each socket in a serial manner.

Hope this helps.

i
 
J

jeremiah johnson

Nicholas said:
You might want to just use different threads to write the details to
different sockets. It would prevent you from having to write the files to
each socket in a serial manner.

He could also take a look at multicasting, and talk with his network
administrator about it. It was designed for just such a situation.
 
D

Dan Tallent

Thx for the idea.
Dan


jeremiah johnson said:
He could also take a look at multicasting, and talk with his network
administrator about it. It was designed for just such a situation.
 
J

Justin Creasy

I don't know much about multicasting, but I can look into it. I am
using TCP for the connections. What would I have to work out with my
network administrator to allow me to use multicasting? This is
something that will potentially be used at multiple sites (schools in
particular) and if something has to be set up specifically in the
network, then that route probably won't work for me. So I will research
multicasting, but any information you have on it would be greatly
appreciated. The thread solution I've messed around with, but that
won't speed up the process of broadcasting any, it will just mean that
I'm slowly writing to 20+ sockets at the same time, vs quickly writing
to one socket at a time.
 
N

naikrovek

Multicasting is definitely what you want, then.

Multicasting is set up at the routers, yes, but it works beautifully.
I'm not sure on the *exact* specifics but the gist of it is that you
stream one copy of your streaming file (music, movie, whatever can
stream) to a specific IP address at your nearest router, and it will
stream one copy of that to the upstream router, which will stream one
copy of the stream to its upstream router, until eventually two
seperate streams are needed. the idea is that eventually your stream
will use the least amount of bandwidth possible (the same as one
stream) then split it out at the destination subnet to all the
computers that subscribe to that stream.

its been years since i've done networking so i could be wrong about the
details but it does exactly what you want. it just requires some
one-time configuration.
 

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

Top