aspose file tools
The moose likes Sockets and Internet Protocols and the fly likes UDP Packet on socket Receive Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Reply Bookmark "UDP Packet on socket Receive" Watch "UDP Packet on socket Receive" New topic
Author

UDP Packet on socket Receive

Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
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.





amerzil co-ed student<br />"Praise be the Code"
Joe Ess
Bartender

Joined: Oct 29, 2001
Posts: 8291

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))


"blabbing like a narcissistic fool with a superiority complex" ~ N.A.
[How To Ask Questions On JavaRanch]
Karen Baog
Ranch Hand

Joined: Mar 02, 2005
Posts: 120
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

Joined: Oct 29, 2001
Posts: 8291

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 ]
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: UDP Packet on socket Receive
 
Similar Threads
online multiplayer snake game: packet overhead
"packet length" or "captured length" in "Jpcap" library !?
file transfer using datagram
TCP, UDP,IP
Can I get source ip address and destination ip address of udp packet?