开发者

Unknown Issue on sending data through tcpclient?

开发者 https://www.devze.com 2023-03-29 03:00 出处:网络
look at this code : private bool SendPack(byte[] _Data) { try { NetworkStream clientStream = Servertcp.GetStream();

look at this code :

  private bool SendPack(byte[] _Data)
    {
        try
        {
            NetworkStream clientStream = Servertcp.GetStream();

            byte[] Pack = new byte[4 + _Data.Length];
            byte[] len = BitConverter.GetBytes(_Data.Length);
            len.CopyTo(Pack, 0);
            buffer.CopyTo(Pack, 4);
            clientStream.Write(Pack, 0, Pack.Length);
            clientStream.Flush();
            return true;
        }
        catch (Exception exp)
        {
            return false;
        }
    }

the function's behavior is strange! sometimes data is recei开发者_如何学JAVAved in client side, sometimes not. the function usually returns true, but in reality no data received, although client is connected to server. when i debuge the function i see that sometimes i lost the pointer after this line : clientStream.Write(Pack, 0, Pack.Length); i mean the pointer does not return to the lines after write...

Any Help would be appreciated.

0

精彩评论

暂无评论...
验证码 换一张
取 消