Captive Imagination
September 06, 2010, 08:37:08 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: jSeamless 1.0 Beta 7 is Available http://www.jseamless.org
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: UDP bug?  (Read 214 times)
0 Members and 1 Guest are viewing this topic.
SockFullOfPennies
Newbie
*
Offline Offline

Posts: 2


View Profile
« on: July 14, 2010, 06:17:34 AM »

I've been using JGN with JME for a while when recently I started getting truncated UDP messages.  They would fail to deserialize on the reader side, killing the connection.

After a bunch of debugging I tracked the problem down to the UDPMessageServer.  This reads data using the DatagramChannel into a local buffer, but this buffer is only 5K.  The datagram being sent was larger than this (in theory up to about 64K -- max size for UDP) after being assembled by the PacketCombiner.  According to the javadoc for the DatagramChannel's read() method:

Quote
If there are more bytes in the datagram than remain in the given buffer then the remainder of the datagram is silently discarded.

Digging a bit deeper, I think there may be a problem on the writer side as well.  The write() method uses the DatagramChannel to send the entire buffer created by the PacketCombiner which (if I'm reading this correctly) could be up to 512K.  But the max size for a datagram is 64K and according to the Java I/O book:

Quote
On the other hand, if you try to send more data from a buffer than can fit into a single datagram, the send( ) method sends nothing and returns 0. send( ) will not fragment the data into multiple UDP packets: it writes everything or nothing. You're probably okay up to 8K of data on a modern system, and you may be okay somewhat beyond that. However, 64K (indeed, a little less than that when space for IP headers and such is set aside) is the absolute maximum that can ever fit into one UDP datagram.
Logged
Tumaini
JGN Developer
Jr. Member
*****
Offline Offline

Posts: 51


View Profile
« Reply #1 on: July 21, 2010, 04:47:20 AM »

That seems like a problem.
Darkfrog is not often frequenting these forums anymore and I don't know alot about the buffers used there, but perhaps you could suggest a fix and test it and perhaps I could commit it if it works well?
Logged
SockFullOfPennies
Newbie
*
Offline Offline

Posts: 2


View Profile
« Reply #2 on: July 29, 2010, 02:44:53 PM »

For my purposes I just changed UDPMessageServer.java to increase the size of the buffer to 64K.  I didn't reduce the size of the PacketCombiner buffer since I don't fully understand the implications of that and the problem is just theoretical at this point.

Increasing the the UDPMessageBuffer size worked for me, but I only have one instance of that class so the extra memory was no big deal. 
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.172 seconds with 20 queries.