Hi,

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 is what I initially came up with, but i know it needs a lot more. Please help me by explaining how to capture a packet and how the decoding process works (like how do i extract packet details, etc). I searched the net but could not find a solution that I can understand properly.

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.