简体   繁体   中英

How to get response length before reading response from socket in java

I am working on MML server, my Task is to read response from MML server. In this case, there is no "End of Response" Character in response. How would i know that that response is ended? Is there any kind of technique to get response length before reading the response. by doing this i want to break my while loop using the response length.

while(true)
{
    try
    {
       char temp = (char) is.read();
       System.out.println(temp);
       responseLine = responseLine + temp;
    }
    catch(Throwable e)
    {
        e.printStackTrace();
        break;
    }
}

I don't know MML, but with streams in general, the ways to recognize end of a message are:

  • "end of message" flag / sequence in the stream
  • a known message header containing information about message length - you then count the bytes / chars
  • end of stream - the sender closes the stream on their end

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM