TCP客户端读取错误

时间:2015-03-20 07:59:29

标签: android tcp

我有问题。在我的IntentService中,我需要阅读一些消息。我从具有TCP连接的服务器收到此消息。我刚刚在这种模式下实现了它:

        byte[] bytes = new byte[1000];

        StringBuilder reader = new StringBuilder();

        int counter = 0;

      while((counter=readeIn.read(bytes))!= -1) //if TCP Socket works
      {
            reader.append(new String(bytes, 0, counter));
            reader.append("\n");
            String req = reader.toString();
            Log.d("String received:",reader);
      }

并且它可以工作但是在logcat中它打印相同的字符串3/4次...我认为这是缓冲区的问题,但我不能使用readLine(),因为服务器没有&# 39; t发给我" \ n" ... 我该怎么解决? 谢谢

0 个答案:

没有答案