简体   繁体   English

在Java中从套接字读取响应之前如何获取响应长度

[英]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. 我在MML服务器上工作,我的任务是从MML服务器读取响应。 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循环。

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: 我不知道MML,但是对于一般的流,识别消息结尾的方法是:

  • "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 流的末尾-发送方在其末端关闭流

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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