Results 1 to 2 of 2
- 11-08-2010, 06:31 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
Decode Binary Packet via TCP Socket
Hi All,
I am kind new to java and have a problem with packet decoding. I am hoping you will be able to help me with this.
I have written a TCP socket listener which seems to be working fine. The listener receives packets from a GPS unit (NMEA, protocol C). I understand the data fields in the protocol. My problem is how to go about decoding the binary data received.
I have tried many ways .. with my limited knowledge, and was not successful. Below i what I initially came up with, but i know it needs a lot more. Please help me by explaining how to capture the packet and how the decoding process works (like how do i extract the packet details, etc). I searched the net but could not find a solution that I can understand properly.
Java Code:InputStream in = evt.getSocket().getInputStream(); // Input OutputStream out = evt.getSocket().getOutputStream(); // Output byte[] buff = new byte[1024]; // Buffer int num = -1; // Bytes read while( (num = in.read(buff)) >= 0 ){ // Not EOS yet // Create file stream FileWriter fstream = new FileWriter("/var/log/binary_packet_dump.txt",true); BufferedWriter bw = new BufferedWriter(fstream); bw.write(new String(buff,0,num)); //Close the output stream bw.close(); }
Thanks.
- 11-09-2010, 02:54 PM #2
Member
- Join Date
- Nov 2010
- Posts
- 2
- Rep Power
- 0
I gess my understanding of the concept is lacking due to my lack of knowledge, but i need to learn how to decode a binary packet received that has been sent to my Java based TCP socket listener.
It is ok even if it is not a NMEA packet, but in general how to go about decoding a packet, as this is the first time I am doing this and I do not have a proper idea where to start.
For e.g. in PHP to decode a binary packet I can use a inbuilt function called `unpack`to extract data from binary string.
So please help me if you can. Again thanks in advance.
Similar Threads
-
decode binary to characters
By greg677 in forum New To JavaReplies: 11Last Post: 04-17-2010, 03:48 PM -
Decode this piece of Code
By mikeyl62 in forum New To JavaReplies: 2Last Post: 02-27-2010, 08:59 PM -
code and decode?
By jeffrey in forum New To JavaReplies: 5Last Post: 08-07-2009, 09:18 AM -
Can't Stop packet from transmitting and unable to understand packet format
By khajalid in forum NetworkingReplies: 2Last Post: 12-22-2008, 03:05 AM -
MimeUtility.decode encoding
By mwildam in forum Advanced JavaReplies: 2Last Post: 08-19-2008, 02:41 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks