Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: reading unformatted data from socket

  1. #1
    Junior Member
    Join Date
    Aug 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default reading unformatted data from socket

    I have a server socket application which listens on particular ip and port. Then I have client socket which reads input from server and give response.
    But my problem is that server do not formatted line termination characters at the end. so when i use buffered reader readline method it hangs. so how should i read the data send by server.
    here server is basically a API(METER).

    Thanks in advance.

    Please reply at earliest.

    I am also enclosing herewith sample request /response between server and client.


    Request: 8/2/2012 3:28:24 PM.60764 (+0.0000 seconds)

    53 0D S.

    Answer: 8/2/2012 3:28:24 PM.87364 (+0.2656 seconds)

    53 50 31 39 35 30 34 37 38 34 0D SP19504784.

    Request: 8/2/2012 3:28:24 PM.92064 (+0.0000 seconds)

    53 48 0D SH.

    Answer: 8/2/2012 3:28:24 PM.02964 (+0.1094 seconds)

    53 48 0D SH.
    Request: 8/2/2012 3:28:26 PM.81164 (+0.0000 seconds)

    CA F0 00 00 00 00 00 00 00 3A Êð.......:

    Answer: 8/2/2012 3:28:26 PM.02964 (+0.2188 seconds)

    C4 00 05 00 C9 31 36 38 C4 B7 B7 3F 2E C9 74 5A Ä...É168Ä··?.ÉtZ
    02 00 02 00 FE FC C9 A1 0D 07 00 FB FF FD FC C9 ....þüÉ¡...ûÿýüÉ
    1E 0E FD FF FE FF FD FC C9 B8 FE 4E FF FA 01 FF ..ýÿþÿýüɸþNÿú.ÿ
    FF B9 D0 F9 F0 3F D0 BF 50 9F ÿ¹Ðùð?пP?


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: reading unformatted data from socket

    If the data being sent is a String and you know how many bytes were sent, you could use the read() method to read the bytes into an array and build a String from the bytes in the array.

    If you don't know the number of bytes being sent, you won't know when to build the String with what has already been received.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: reading unformatted data from socket

    Also posted at reading unformatted data(i.e that string do not having line termination characters)
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Help reading in data
    By toolman87 in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: August 30th, 2011, 06:41 PM
  2. Send and Receive data from socket simultaneously
    By bigmac025 in forum File I/O & Other I/O Streams
    Replies: 0
    Last Post: March 25th, 2011, 05:18 PM
  3. Problem reading from server socket
    By glauber in forum Java Networking
    Replies: 0
    Last Post: February 15th, 2011, 12:54 PM
  4. Reading Chunks of Data
    By icu222much in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 22nd, 2010, 08:39 PM
  5. Storing data from a socket to a file in real time
    By colossusdub in forum Java Networking
    Replies: 0
    Last Post: March 2nd, 2010, 09:10 AM

Tags for this Thread