Forums Register Login

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

+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Experts! Anyone, please?

BTW: here I got some answers:

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

Thank you.

Nathan.
Something must be done about this. Let's start by reading this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 3408 times.
Similar Threads
java out of memory exception
need to recieve 100 000 of packets per second
TCP or UDP
Multicast UDP Packet Loss
nio and file transfers
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 09:43:09.