aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes Networking - Connected UDP channels? DatagramChannel.connect(...) Linux vs Windows Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "Networking - Connected UDP channels? DatagramChannel.connect(...) Linux vs Windows" Watch "Networking - Connected UDP channels? DatagramChannel.connect(...) Linux vs Windows" New topic
Author

Networking - Connected UDP channels? DatagramChannel.connect(...) Linux vs Windows

Nathan Levi
Greenhorn

Joined: Apr 02, 2008
Posts: 11
Hello Dukes!

Question:

Can someone please confirm that it is in fact possible to use java nio DatagramChannel in connected mode on Windows on a UDP server side, using non-blocking channels + select(), with multiple UDP clients?

I have code running on Linux as expected, but on Windows it is just bizarre;

It seems the bottom line question is:

Situation:
1) imagine you have 2 DatagramChannel s;
2) both channels are bound to the same localAddress;
3) both have socket.setReuseAddress(true);
4) first DatagramChannel is CONNECTED via channel.connect( remoteAddress );
5) second DatagramChannel is NOT connected;
6) now UDP packets start to arrive from the remoteAddress;
7) what happens? which channel will receive the packet, if at all? how select() will react? etc?

My experience is like this:

Linux answer:
a) first channel, that is, CONNECTED channel - will receive the packet and will activate select() with key.isReadble() for all traffic coming from the remoteAddress;
b) all other traffic NOT coming from the remoteAddress (that is, from NOT connected senders) will be received by the second channel, and it will also activate select() and key.isReadble() appropriately;

Windows answer:
random bizarre patterns; namely:
1) sometimes first channel receives the packet
2) sometimes second channel receives the packet
3) sometimes both channel appear to hang and do not respond to any kinds of packets - coming from either remoteAddress or otherwise;

Windows workaround:
of course, one can go back to NON connected channels, but then you can really have only SINGLE DatagramChannel on the server, servicing multiple clients, which is not the NIO way.

NOTE:
I tried this on both JDK6 and JDK7, on multiple Linux flavors as well as Windows XP, 2000 and 2003; nio on Linux consitently works; nio on Windows - consistently NOT. Also, I tried numerous permutations (about 7 different nio patterns) in the way select() / register() / interestOps() are managed; result is all the same, Linux works, Windows does not; I am at the point where I will need to try this code in C# to see if this is java or Windows problem; and I hope your answer can save me form this

Any answer or experience you have would be greatly appreciated;

Thank you very much for your help;

The End.
Nathan Levi
Greenhorn

Joined: Apr 02, 2008
Posts: 11
Experts! Anyone, please?

BTW: here I got some answers:

http://forums.sun.com/thread.jspa?messageID=10676251

Thank you.

Nathan.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Networking - Connected UDP channels? DatagramChannel.connect(...) Linux vs Windows
 
Similar Threads
nio and file transfers
Multicast UDP Packet Loss
java out of memory exception
TCP or UDP
need to recieve 100 000 of packets per second