gpt4 book ai didi

c# - 接收字符串作为内存流并进行编码后,将添加更多字符

转载 作者:行者123 更新时间:2023-12-03 11:59:13 26 4
gpt4 key购买 nike

我构建了一个应用程序,该应用程序通过以下代码接收数据并将其发送到服务器,并且我注意到,当我取回字符串时,它会以MemoryStream的形式向字符串添加一些字符。这是代码和调试信息:

客户:

            while (true)
{
if (stream.DataAvailable)
{
while ((i = stream.Read(ByteBuffer, 0, ByteBuffer.Length)) != 0)
{
ms.Write(ByteBuffer, 0, ByteBuffer.Length);
if (stream.DataAvailable)
continue;
else
break;
}
ToReturn = Encoding.ASCII.GetString(ms.ToArray());

return ToReturn;
}
}
}

服务器:
            MemoryStream response = new MemoryStream();
response = Protocol.ProcessRequest(dataRecieved, ClientAddr);
#endregion
Console.WriteLine("Trying to send back response." + Encoding.ASCII.GetString(response.ToArray()));
stream.Flush();
response.WriteTo(stream);

我已经检查了调试器以及在控制台上显示的内容:
发送的信息很好,例如: response.Id^Name^Type^SubType^Description^AddedBy^AddedDT^IsSpecial^Amount@1^VGA cable^cable^display^Very old and common display cable.^Aviv^14/01/2019 22:04:34^False^3345@2^HDMI cable^cable^display^newer and better display cable. can pass network, audio and info.^Aviv^14/01/2019 22:05:30^False^4793
,但在套接字另一端(客户端)上收到的信息是: Id^Name^Type^SubType^Description^AddedBy^AddedDT^IsSpecial^Amount@1^VGA cable^cable^display^Very old and common display cable.^Aviv^14/01/2019 22:04:34^False^3345@2^HDMI cable^cable^display^newer and better display cable. can pass network, audio and info.^Aviv^14/01/2019 22:05:30^False^4793alse^4
-最后加上这些( alse^4)几个字符。谁能告诉我编码问题是什么?谢谢。

再次:来自服务器的输出很好

最佳答案

//ms.Write(ByteBuffer, 0, ByteBuffer.Length);
ms.Write(ByteBuffer, 0, i);

关于c# - 接收字符串作为内存流并进行编码后,将添加更多字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54735474/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com