- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在编写客户端-服务器通信的代码。客户端向服务器询问一些内容,然后服务器每隔几毫秒响应一次(在我的问题情况下为50)。
我正在使用TcpClient连接客户端和服务器,并使用BinaryWriter / Reader在TcpClient流(网络流)上进行写入和读取。
我每50毫秒发送一次约100 ko的数据(实际上,我尝试这样做),即约2000 mo / s。客户端和服务器通过rj45线连接,并且客户端防火墙已禁用。
我的问题是BinaryWriter.Write(myString)最少需要5毫秒,最多2500毫秒。因此,我尝试将TcpClient Send / ReceiveBufferSize增加到20MB(默认值为8MB),并且NoDelay = true,这比以前要好一些(之前要花5秒钟),但还不算好。
编写是如此不规则的事实使我觉得缓冲区已满,BinaryWriter正在等待它清空一些,因此在客户端,我在流上执行ReadString,然后在线程中处理数据,但问题仍然存在。
码:
服务器端:
private void traitementEnvois()
{
while (true)
{
//some processing and wait for data to send
NetworkStream stream = Client.GetStream();
using (BinaryWriter writer = new BinaryWriter(stream, Encoding.UTF8, true))
{
while (!_envoisATraiter.IsEmpty) //ConcurrentQueue for data to send
{
String jsonAEnvoyer;
_envoisATraiter.TryDequeue(out jsonAEnvoyer);
if (jsonAEnvoyer != null)
{
Stopwatch chrono = new Stopwatch();
chrono.Start();
writer.Write(jsonAEnvoyer);
long elaspedMs = chrono.ElapsedMilliseconds;
chrono.Stop();
EcritureEvenement.loggerEvenement("written in " + elaspedMs, TypesEvenements.DEBUG, "EnvoiParClient.traitementEnvois"); //log the event
}
}
}
}
}
private void traitementStreamServeur(TcpClient server)
{
NetworkStream stream = server.GetStream();
BinaryReader reader = new BinaryReader(stream);
while (true)
{
if (stream.DataAvailable)
{
String messageJson = reader.ReadString(); //read data from the stream
new Thread(() => traiterMessageRecu(messageJson)).Start(); //process data
}
else
{
Thread.Sleep(10);
}
}
}
DEBUG 04-23-2014 14:18:50.332 written in 9 ms
DEBUG 04-23-2014 14:18:50.485 written in 8 ms
DEBUG 04-23-2014 14:18:50.658 written in 9 ms
DEBUG 04-23-2014 14:18:50.816 written in 6 ms
DEBUG 04-23-2014 14:18:51.009 written in 4 ms
DEBUG 04-23-2014 14:18:51.153 written in 24 ms
DEBUG 04-23-2014 14:18:51.305 written in 4 ms
DEBUG 04-23-2014 14:18:51.456 written in 9 ms
DEBUG 04-23-2014 14:18:51.638 written in 14 ms
DEBUG 04-23-2014 14:18:51.797 written in 62 ms
DEBUG 04-23-2014 14:18:51.955 written in 63 ms
DEBUG 04-23-2014 14:18:52.066 written in 13 ms
DEBUG 04-23-2014 14:18:52.309 written in 77 ms
DEBUG 04-23-2014 14:18:52.508 written in 58 ms
DEBUG 04-23-2014 14:18:52.643 written in 81 ms
DEBUG 04-23-2014 14:18:52.750 written in 18 ms
DEBUG 04-23-2014 14:18:53.007 written in 108 ms
DEBUG 04-23-2014 14:18:53.201 written in 124 ms
DEBUG 04-23-2014 14:18:53.300 written in 27 ms
DEBUG 04-23-2014 14:18:53.477 written in 49 ms
DEBUG 04-23-2014 14:18:53.615 written in 56 ms
DEBUG 04-23-2014 14:18:53.871 written in 129 ms
DEBUG 04-23-2014 14:18:53.922 written in 36 ms
DEBUG 04-23-2014 14:18:54.196 written in 121 ms
DEBUG 04-23-2014 14:18:54.361 written in 101 ms
DEBUG 04-23-2014 14:18:54.580 written in 148 ms
DEBUG 04-23-2014 14:18:54.773 written in 154 ms
DEBUG 04-23-2014 14:18:54.784 written in 11 ms
DEBUG 04-23-2014 14:18:55.077 written in 103 ms
DEBUG 04-23-2014 14:18:55.327 written in 192 ms
DEBUG 04-23-2014 14:18:55.475 written in 147 ms
DEBUG 04-23-2014 14:18:55.501 written in 25 ms
DEBUG 04-23-2014 14:18:55.703 written in 92 ms
DEBUG 04-23-2014 14:18:56.326 written in 578 ms
DEBUG 04-23-2014 14:18:56.953 written in 626 ms
DEBUG 04-23-2014 14:18:57.400 written in 447 ms
DEBUG 04-23-2014 14:18:58.049 written in 648 ms
DEBUG 04-23-2014 14:18:58.238 written in 189 ms
DEBUG 04-23-2014 14:18:58.952 written in 713 ms
DEBUG 04-23-2014 14:18:59.646 written in 694 ms
DEBUG 04-23-2014 14:18:59.995 written in 348 ms
DEBUG 04-23-2014 14:19:00.518 written in 523 ms
DEBUG 04-23-2014 14:19:01.350 written in 831 ms
DEBUG 04-23-2014 14:19:01.620 written in 270 ms
DEBUG 04-23-2014 14:19:02.220 written in 599 ms
DEBUG 04-23-2014 14:19:02.516 written in 295 ms
DEBUG 04-23-2014 14:19:02.689 written in 172 ms
DEBUG 04-23-2014 14:19:02.880 written in 191 ms
DEBUG 04-23-2014 14:19:04.308 written in 1427 ms
DEBUG 04-23-2014 14:19:04.331 written in 23 ms
DEBUG 04-23-2014 14:19:04.345 written in 13 ms
DEBUG 04-23-2014 14:19:04.351 written in 6 ms
DEBUG 04-23-2014 14:19:04.370 written in 18 ms
DEBUG 04-23-2014 14:19:04.477 written in 107 ms
DEBUG 04-23-2014 14:19:05.553 written in 1075 ms
DEBUG 04-23-2014 14:19:06.903 written in 1350 ms
DEBUG 04-23-2014 14:19:07.168 written in 264 ms
DEBUG 04-23-2014 14:19:07.565 written in 396 ms
DEBUG 04-23-2014 14:19:09.073 written in 1507 ms
DEBUG 04-23-2014 14:19:09.934 written in 861 ms
DEBUG 04-23-2014 14:19:10.676 written in 742 ms
DEBUG 04-23-2014 14:19:11.794 written in 1118 ms
DEBUG 04-23-2014 14:19:12.247 written in 452 ms
DEBUG 04-23-2014 14:19:13.171 written in 924 ms
DEBUG 04-23-2014 14:19:13.514 written in 342 ms
DEBUG 04-23-2014 14:19:13.779 written in 265 ms
DEBUG 04-23-2014 14:19:14.762 written in 983 ms
DEBUG 04-23-2014 14:19:14.799 written in 36 ms
DEBUG 04-23-2014 14:19:16.525 written in 1726 ms
DEBUG 04-23-2014 14:19:17.029 written in 503 ms
DEBUG 04-23-2014 14:19:17.545 written in 515 ms
DEBUG 04-23-2014 14:19:17.624 written in 79 ms
DEBUG 04-23-2014 14:19:17.959 written in 335 ms
DEBUG 04-23-2014 14:19:18.864 written in 904 ms
DEBUG 04-23-2014 14:19:20.285 written in 1420 ms
DEBUG 04-23-2014 14:19:20.307 written in 21 ms
DEBUG 04-23-2014 14:19:20.359 written in 52 ms
DEBUG 04-23-2014 14:19:20.722 written in 363 ms
DEBUG 04-23-2014 14:19:21.172 written in 449 ms
DEBUG 04-23-2014 14:19:21.824 written in 652 ms
DEBUG 04-23-2014 14:19:22.000 written in 176 ms
DEBUG 04-23-2014 14:19:22.499 written in 498 ms
DEBUG 04-23-2014 14:19:23.368 written in 869 ms
DEBUG 04-23-2014 14:19:23.773 written in 404 ms
DEBUG 04-23-2014 14:19:24.835 written in 1062 ms
DEBUG 04-23-2014 14:19:24.927 written in 91 ms
DEBUG 04-23-2014 14:19:24.995 written in 68 ms
DEBUG 04-23-2014 14:19:25.514 written in 518 ms
DEBUG 04-23-2014 14:19:27.232 written in 1718 ms
最佳答案
好的,我发现客户端的处理量很大。在那之前并没有真正测试过它,所以我不知道它花了这么长时间。
在我注释了数据过程之后,线程中的过程大约需要29秒,这是日志的外观:DEBUG 04-23-2014 14:45:53.112 written in 4 ms
DEBUG 04-23-2014 14:45:53.276 written in 6 ms
DEBUG 04-23-2014 14:45:53.449 written in 8 ms
DEBUG 04-23-2014 14:45:53.636 written in 17 ms
DEBUG 04-23-2014 14:45:53.813 written in 4 ms
DEBUG 04-23-2014 14:45:54.022 written in 5 ms
DEBUG 04-23-2014 14:45:54.180 written in 7 ms
DEBUG 04-23-2014 14:45:54.352 written in 6 ms
DEBUG 04-23-2014 14:45:54.529 written in 19 ms
DEBUG 04-23-2014 14:45:54.733 written in 6 ms
DEBUG 04-23-2014 14:45:54.905 written in 7 ms
DEBUG 04-23-2014 14:45:55.088 written in 14 ms
DEBUG 04-23-2014 14:45:55.281 written in 3 ms
DEBUG 04-23-2014 14:45:55.442 written in 4 ms
DEBUG 04-23-2014 14:45:55.621 written in 4 ms
DEBUG 04-23-2014 14:45:55.819 written in 7 ms
DEBUG 04-23-2014 14:45:56.007 written in 7 ms
DEBUG 04-23-2014 14:45:56.175 written in 5 ms
DEBUG 04-23-2014 14:45:56.363 written in 18 ms
DEBUG 04-23-2014 14:45:56.581 written in 7 ms
DEBUG 04-23-2014 14:45:56.759 written in 7 ms
DEBUG 04-23-2014 14:45:56.939 written in 16 ms
DEBUG 04-23-2014 14:45:57.161 written in 5 ms
DEBUG 04-23-2014 14:45:57.304 written in 5 ms
DEBUG 04-23-2014 14:45:57.488 written in 7 ms
DEBUG 04-23-2014 14:45:57.642 written in 8 ms
DEBUG 04-23-2014 14:45:57.837 written in 4 ms
DEBUG 04-23-2014 14:45:57.991 written in 7 ms
DEBUG 04-23-2014 14:45:58.148 written in 4 ms
DEBUG 04-23-2014 14:45:58.361 written in 6 ms
DEBUG 04-23-2014 14:45:58.534 written in 5 ms
DEBUG 04-23-2014 14:45:58.737 written in 21 ms
DEBUG 04-23-2014 14:45:58.888 written in 5 ms
DEBUG 04-23-2014 14:45:59.094 written in 5 ms
DEBUG 04-23-2014 14:45:59.276 written in 4 ms
DEBUG 04-23-2014 14:45:59.451 written in 5 ms
DEBUG 04-23-2014 14:45:59.629 written in 4 ms
DEBUG 04-23-2014 14:45:59.813 written in 6 ms
DEBUG 04-23-2014 14:45:59.994 written in 11 ms
DEBUG 04-23-2014 14:46:00.162 written in 5 ms
DEBUG 04-23-2014 14:46:00.367 written in 4 ms
DEBUG 04-23-2014 14:46:00.560 written in 12 ms
DEBUG 04-23-2014 14:46:00.738 written in 5 ms
DEBUG 04-23-2014 14:46:00.932 written in 7 ms
DEBUG 04-23-2014 14:46:01.120 written in 6 ms
DEBUG 04-23-2014 14:46:01.311 written in 8 ms
DEBUG 04-23-2014 14:46:01.483 written in 4 ms
DEBUG 04-23-2014 14:46:01.671 written in 4 ms
DEBUG 04-23-2014 14:46:01.864 written in 7 ms
DEBUG 04-23-2014 14:46:02.078 written in 4 ms
DEBUG 04-23-2014 14:46:02.237 written in 6 ms
DEBUG 04-23-2014 14:46:02.415 written in 18 ms
DEBUG 04-23-2014 14:46:02.612 written in 7 ms
DEBUG 04-23-2014 14:46:02.789 written in 4 ms
DEBUG 04-23-2014 14:46:02.941 written in 4 ms
DEBUG 04-23-2014 14:46:03.111 written in 4 ms
DEBUG 04-23-2014 14:46:03.293 written in 5 ms
DEBUG 04-23-2014 14:46:03.477 written in 5 ms
DEBUG 04-23-2014 14:46:03.609 written in 5 ms
DEBUG 04-23-2014 14:46:03.791 written in 5 ms
DEBUG 04-23-2014 14:46:03.956 written in 4 ms
DEBUG 04-23-2014 14:46:04.140 written in 18 ms
DEBUG 04-23-2014 14:46:04.319 written in 7 ms
DEBUG 04-23-2014 14:46:04.466 written in 5 ms
DEBUG 04-23-2014 14:46:04.630 written in 5 ms
DEBUG 04-23-2014 14:46:04.785 written in 17 ms
DEBUG 04-23-2014 14:46:04.938 written in 5 ms
DEBUG 04-23-2014 14:46:05.094 written in 7 ms
DEBUG 04-23-2014 14:46:05.277 written in 7 ms
DEBUG 04-23-2014 14:46:05.383 written in 9 ms
DEBUG 04-23-2014 14:46:05.539 written in 4 ms
DEBUG 04-23-2014 14:46:05.705 written in 4 ms
DEBUG 04-23-2014 14:46:05.920 written in 8 ms
DEBUG 04-23-2014 14:46:06.133 written in 4 ms
DEBUG 04-23-2014 14:46:06.301 written in 5 ms
DEBUG 04-23-2014 14:46:06.443 written in 8 ms
DEBUG 04-23-2014 14:46:06.661 written in 6 ms
DEBUG 04-23-2014 14:46:06.855 written in 5 ms
DEBUG 04-23-2014 14:46:07.048 written in 6 ms
DEBUG 04-23-2014 14:46:07.242 written in 21 ms
DEBUG 04-23-2014 14:46:07.440 written in 8 ms
DEBUG 04-23-2014 14:46:07.619 written in 5 ms
DEBUG 04-23-2014 14:46:07.792 written in 17 ms
DEBUG 04-23-2014 14:46:07.988 written in 3 ms
DEBUG 04-23-2014 14:46:08.163 written in 4 ms
DEBUG 04-23-2014 14:46:08.343 written in 4 ms
DEBUG 04-23-2014 14:46:08.509 written in 7 ms
DEBUG 04-23-2014 14:46:08.703 written in 5 ms
DEBUG 04-23-2014 14:46:08.906 written in 6 ms
DEBUG 04-23-2014 14:46:09.108 written in 5 ms
DEBUG 04-23-2014 14:46:09.257 written in 5 ms
DEBUG 04-23-2014 14:46:09.466 written in 6 ms
DEBUG 04-23-2014 14:46:09.636 written in 6 ms
DEBUG 04-23-2014 14:46:09.821 written in 5 ms
DEBUG 04-23-2014 14:46:10.011 written in 8 ms
DEBUG 04-23-2014 14:46:10.167 written in 12 ms
DEBUG 04-23-2014 14:46:10.406 written in 24 ms
DEBUG 04-23-2014 14:46:10.511 written in 4 ms
DEBUG 04-23-2014 14:46:10.691 written in 4 ms
DEBUG 04-23-2014 14:46:10.894 written in 5 ms
DEBUG 04-23-2014 14:46:11.113 written in 9 ms
DEBUG 04-23-2014 14:46:11.286 written in 5 ms
DEBUG 04-23-2014 14:46:11.469 written in 15 ms
DEBUG 04-23-2014 14:46:11.669 written in 4 ms
DEBUG 04-23-2014 14:46:11.826 written in 7 ms
DEBUG 04-23-2014 14:46:12.008 written in 9 ms
DEBUG 04-23-2014 14:46:12.142 written in 11 ms
DEBUG 04-23-2014 14:46:12.322 written in 4 ms
DEBUG 04-23-2014 14:46:12.508 written in 7 ms
DEBUG 04-23-2014 14:46:12.673 written in 13 ms
DEBUG 04-23-2014 14:46:12.836 written in 5 ms
DEBUG 04-23-2014 14:46:13.018 written in 6 ms
DEBUG 04-23-2014 14:46:13.191 written in 4 ms
DEBUG 04-23-2014 14:46:13.359 written in 5 ms
DEBUG 04-23-2014 14:46:13.529 written in 4 ms
DEBUG 04-23-2014 14:46:13.679 written in 5 ms
DEBUG 04-23-2014 14:46:13.849 written in 10 ms
DEBUG 04-23-2014 14:46:14.036 written in 7 ms
DEBUG 04-23-2014 14:46:14.218 written in 6 ms
DEBUG 04-23-2014 14:46:14.406 written in 14 ms
DEBUG 04-23-2014 14:46:14.613 written in 5 ms
DEBUG 04-23-2014 14:46:14.785 written in 4 ms
DEBUG 04-23-2014 14:46:14.972 written in 6 ms
DEBUG 04-23-2014 14:46:15.136 written in 5 ms
DEBUG 04-23-2014 14:46:15.333 written in 5 ms
DEBUG 04-23-2014 14:46:15.481 written in 4 ms
DEBUG 04-23-2014 14:46:15.619 written in 3 ms
DEBUG 04-23-2014 14:46:15.833 written in 5 ms
DEBUG 04-23-2014 14:46:16.034 written in 6 ms
DEBUG 04-23-2014 14:46:16.199 written in 5 ms
DEBUG 04-23-2014 14:46:16.425 written in 5 ms
DEBUG 04-23-2014 14:46:16.583 written in 4 ms
DEBUG 04-23-2014 14:46:16.755 written in 7 ms
DEBUG 04-23-2014 14:46:16.939 written in 6 ms
DEBUG 04-23-2014 14:46:17.126 written in 5 ms
DEBUG 04-23-2014 14:46:17.278 written in 5 ms
DEBUG 04-23-2014 14:46:17.426 written in 6 ms
DEBUG 04-23-2014 14:46:17.632 written in 4 ms
DEBUG 04-23-2014 14:46:17.776 written in 5 ms
DEBUG 04-23-2014 14:46:17.960 written in 13 ms
DEBUG 04-23-2014 14:46:18.129 written in 4 ms
DEBUG 04-23-2014 14:46:18.306 written in 4 ms
DEBUG 04-23-2014 14:46:18.500 written in 3 ms
DEBUG 04-23-2014 14:46:18.670 written in 26 ms
DEBUG 04-23-2014 14:46:18.832 written in 4 ms
DEBUG 04-23-2014 14:46:19.017 written in 5 ms
DEBUG 04-23-2014 14:46:19.203 written in 18 ms
DEBUG 04-23-2014 14:46:19.399 written in 24 ms
DEBUG 04-23-2014 14:46:19.531 written in 4 ms
DEBUG 04-23-2014 14:46:19.701 written in 5 ms
DEBUG 04-23-2014 14:46:19.881 written in 21 ms
DEBUG 04-23-2014 14:46:20.063 written in 6 ms
DEBUG 04-23-2014 14:46:20.217 written in 5 ms
DEBUG 04-23-2014 14:46:20.372 written in 5 ms
DEBUG 04-23-2014 14:46:20.536 written in 4 ms
DEBUG 04-23-2014 14:46:20.701 written in 3 ms
DEBUG 04-23-2014 14:46:20.899 written in 4 ms
DEBUG 04-23-2014 14:46:21.096 written in 4 ms
DEBUG 04-23-2014 14:46:21.263 written in 5 ms
DEBUG 04-23-2014 14:46:21.473 written in 8 ms
DEBUG 04-23-2014 14:46:21.645 written in 17 ms
DEBUG 04-23-2014 14:46:21.861 written in 15 ms
DEBUG 04-23-2014 14:46:22.024 written in 5 ms
DEBUG 04-23-2014 14:46:22.226 written in 11 ms
DEBUG 04-23-2014 14:46:22.395 written in 7 ms
DEBUG 04-23-2014 14:46:22.560 written in 5 ms
DEBUG 04-23-2014 14:46:22.758 written in 8 ms
DEBUG 04-23-2014 14:46:22.889 written in 11 ms
DEBUG 04-23-2014 14:46:23.042 written in 5 ms
DEBUG 04-23-2014 14:46:23.263 written in 4 ms
DEBUG 04-23-2014 14:46:23.468 written in 33 ms
DEBUG 04-23-2014 14:46:24.622 written in 9 ms
DEBUG 04-23-2014 14:46:24.812 written in 24 ms
DEBUG 04-23-2014 14:46:24.947 written in 4 ms
DEBUG 04-23-2014 14:46:25.149 written in 4 ms
DEBUG 04-23-2014 14:46:25.315 written in 7 ms
DEBUG 04-23-2014 14:46:25.490 written in 5 ms
DEBUG 04-23-2014 14:46:25.670 written in 12 ms
DEBUG 04-23-2014 14:46:25.838 written in 3 ms
DEBUG 04-23-2014 14:46:25.995 written in 6 ms
DEBUG 04-23-2014 14:46:26.199 written in 4 ms
DEBUG 04-23-2014 14:46:26.402 written in 5 ms
DEBUG 04-23-2014 14:46:26.576 written in 7 ms
DEBUG 04-23-2014 14:46:26.753 written in 6 ms
DEBUG 04-23-2014 14:46:26.936 written in 7 ms
DEBUG 04-23-2014 14:46:27.144 written in 6 ms
DEBUG 04-23-2014 14:46:27.320 written in 6 ms
DEBUG 04-23-2014 14:46:27.486 written in 11 ms
DEBUG 04-23-2014 14:46:27.703 written in 7 ms
看起来很棒。客户端在处理这么多线程和太多内存/ CPU使用上遇到麻烦。
谢谢大家阅读我的问题。
关于c# - Networkstream不规则速度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23244312/
我希望有人可以解释这种行为,或者它是否可能是 .NET 中的错误。 由于夏令时而及时向后移动意味着 NetworkStream 不注意其属性 ReadTimeout,并且在此代码的情况下会导致循环旋转
我需要从 NetworkStream 中读取,它会随机发送数据,数据包的大小也会不断变化。我正在实现一个多线程应用程序,其中每个线程都有自己的流来读取。如果流中没有数据,应用程序应该一直等待数据到达。
我编写了以下函数来使用 NetworkStream 的异步读取函数(BeginRead 和 EndRead)实现超时功能。它工作正常,直到我注释掉行 Trace.WriteLine("bytesRea
如果 Internet 上的 B 类网络的子网掩码为 255.255.248.0,那么每个子网的最大主机数是多少?(一) 1022(乙) 1023(三) 2046(D) 2047 任何人都可以告诉我如
我读过一个 Tcp Echo Server 的例子,有些事情我不清楚。 TcpClient client = null; NetworkStream netStream = null; try {
This question already has answers here: NetworkStream.ReadAsync with a cancellation token never canc
我正在使用套接字编写一个简单的聊天程序。当我发送长消息时,随后刷新流和短消息,长消息的末尾会附加到短消息中。它看起来像这样: 发送“aaasdsd” 接收“aaasdsd” 发送“bb” 接收“bba
我目前正在从事一个网络项目,我在其中制定了一个二进制协议(protocol)。我的数据包看起来像这样:[1 字节类型][2 字节索引][2 字节长度][长度字节数据] 这是我接收数据包的代码: Net
我的应用程序打开一个 NetworkStream 和一个 StreamWriter 以将 HL7 消息发送到服务。此服务接收 HL7 消息并始终发回确认。我遇到以下问题:在发送 HL7 消息(有效,我
在同一台计算机上,我有 2 个控制台应用程序。 (客户端向服务器发送文件) 在开始之前,我只想提一下我正在使用这两个 async 函数: 从 NetworkStream 读取: public sta
我正在编写一个简单的客户端-服务器应用程序,在查看 MSDN 文档时,我遇到了一些有趣的流类型... http://msdn.microsoft.com/en-us/library/system.io
早上好 我需要一些建议,我正在使用从 TcpClient 流式传输的 networkStream,一切正常,但后来我需要其他地方的一些功能,这需要关闭流。一旦连接关闭,我似乎找不到重新打开连接的方法。
只是尝试使用 Networkstream,这是我写的一个简单代码: 客户端: TcpClient c = new TcpClient(); c.Connect("10.0
我使用 Moq 和 NUnit 作为单元测试框架。 我写了一个方法,将 NetworkStream 对象作为参数: public static void ReadDataIntoBuffer(Netw
好吧,所以我理解 TCP 是基于流而不是基于消息的整个想法 - 我不关心这个。 我想做的是简单地序列化一些东西,然后通过网络将它发送到另一个使用相同的基于消息的协议(protocol)的应用程序。 问
NetworkStream 从套接字缓冲区读取不应该存在的数据时出现问题。顺便说一句,我正在发送非常大的缓冲区。现在我刚刚在本地主机上进行测试。 这是我读取数据的方式,前 4 个字节包含消息的长度,然
我使用 TcpClient 和 NetworkStream 为我们的游戏创建了一个简单的持久套接字连接。正常连接、发送消息和断开连接(退出应用程序/服务器关闭/等)都没有问题。 但是,我遇到了一些问题
有问题的数据是一个 PNG 文件,前缀为 int 大小。 -Sending: ns.Write(BitConverter.GetBytes((int)data.Length),0,4); ns.Wri
NetworkStream.DataAvailable 是否知道发送方的发送缓冲区是否为空?或者它只是简单地指示接收方的读取缓冲区是否有数据?我的假设是后者... 具体来说,对于一些涉及正在进行的对话
我有一个类,它包装了一个 Stream 实例,所以我可以用它来包装 FileStreams 和 NetworkStreams。现在,我想测试流是否仍在传递任何数据,换句话说,我想测试 NetworkS
我是一名优秀的程序员,十分优秀!