Results 1 to 2 of 2
  1. #1
    maxice is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Question 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.

  2. #2
    maxice is offline Member
    Join Date
    Nov 2010
    Posts
    2
    Rep Power
    0

    Default

    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

  1. decode binary to characters
    By greg677 in forum New To Java
    Replies: 11
    Last Post: 04-17-2010, 03:48 PM
  2. Decode this piece of Code
    By mikeyl62 in forum New To Java
    Replies: 2
    Last Post: 02-27-2010, 08:59 PM
  3. code and decode?
    By jeffrey in forum New To Java
    Replies: 5
    Last Post: 08-07-2009, 09:18 AM
  4. Replies: 2
    Last Post: 12-22-2008, 03:05 AM
  5. MimeUtility.decode encoding
    By mwildam in forum Advanced Java
    Replies: 2
    Last Post: 08-19-2008, 02:41 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •