Sockets and Channels?
Hi,
I have just completed the chapter about 'Channels' in the book I am reading. I was completely new to these since I had never seen them or heard of them before! Thus I am feeling quite confused on when these should be used and why!
Basically each time I asked networking question I always got the same answer, that is 'sockets'. Socket programming is quite strait forward in Java and in my opinion not that much complicated. However Channels, which for me are completely new, seem to be very complicated! Also it seem that I can achieve with Sockets all that I can achieve with Channels with the only difference of 'non-Blocking' which I do understand, but maybe on giving it the just amount of importance!
Thanks for any comments,
Regards,
Sim085
[793 byte] By [
sim085a] at [2007-11-27 6:38:00]

# 1
I'm not all too good with NIO (Channels) but I think I can answer you.
Channels are event driven, so no need for a separate thread to wait for connections (lots of waiting), one thread per a connection to do the communication (and generally do a lot of waiting) etc. Everything can be done in one thread, selector will pick the proper channel when an event occurs. Also, sometimes you might need non-blocking reads, as you said you can't achieve those with Sockets.
...someone correct/fill me if I said anything wrong/incomplete....
# 2
Thanks for your reply, it does help me a lot.
I did understand the thing about the non-blocking, etc. However I did not catch the event thing maybe because I am so new to this type of syntax (saw it very complicated to say the truth).
Anywasy, Something event driven is nice to have, altough I think it changes the whole way I think of sockets for a network application :) I'll try reading some more articles on this altogh not finding a lot on the internet!
Anyways thanks again,
Regards,
Sim085