TCPClient接收不完整的字符串 [英] TCPClient receiving incomplete string

查看:297
本文介绍了TCPClient接收不完整的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到问题 收到TCPClinet的字符串。这是我的客户端代码

I am having problem receiving string with TCPClinet. Here is my client code

var stream = tcpclient.GetStream();

            var bufferSize = 4096;
            var buffer = new byte[bufferSize];
            int count;

            string strreturn = string.Empty;

            while (true)
            {
                count = stream.Read(buffer, 0, bufferSize);

                

                if (count > 0 )
                {

                    strreturn += Encoding.ASCII.GetString(buffer);


                }
                else
                {
                    break;
                }
            }

            return strreturn;


来自服务器的字符串看起来很好但是当我从另一端收到它时它不完整。我怀疑存在某种超时。

The string from the server look fine but when i received it from the other end it is incomplete. I suspect there is a timeout of some sort.

推荐答案

增加缓冲区

http://chanmingman.wordpress.com/2009/04/12/transfer-picture-jpg-over-the-network-using-networkstream/

chanmm


这篇关于TCPClient接收不完整的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆