• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

UDP Packet on socket Receive

 
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a DataGramSocket and calls its receive method to get packets.
What I'm not clear yet (being new on this) is decoding the data.

I've read a bit on UDP, but what I want to know is whether, by using the .receive method it also captures the IP header and UDP header part.

I'm receiving signed bytes. Do I then perform two's complement on the negative numbers? I did this, and reading at all the bits I could not see even the source address. In my text setup, the source use the 192.168.0.x address. For 192, I would expect to see something like 11000000

Again, does the packet (when .receive is used) also capture the headers?
For example, the first byte I get is 00001000, which should correspong to IP version.
This doesn't seem to be correct, as I would think that in UDP it would be decimal 4 (for IPv4). Perhaps, I'm missing something here.

I don't know what all those bytes correspond to.

I'm sooo confused.



 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karen Baog:
Again, does the packet (when .receive is used) also capture the headers?



Are you talking about an instance of java.net.DatagramPacket? It has several methods to get information about the packet, but nothing like IP version. Are you looking at the results of getData()? That only contains the data portion of the packet (see diagrams here))
 
Karen Baog
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using the DatagramPacket.



So, I'm actually getting the data portion (the actual message) of the packet? And that the IP and UDP headers are not included?
[ August 01, 2005: Message edited by: Karen Baog ]
 
Joe Ess
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Karen Baog:

So, I'm actually getting the data portion (the actual message) of the packet? And that the IP and UDP headers are not included?



You are correct. The Java Tutorial has a chapter on Datagrams in the Custom Networking tutorial, and there's a couple of simple examples at the Java Almanac. Maybe they will help you sort things out.
[ August 02, 2005: Message edited by: Joe Ess ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic