从 gprs 连接接收数据的延迟
我正在用 C# 编写一个解析器。它接收并发送一个最大长度= 100
的数据包。然而,每个数据包之间(接收和发送)的时间间隔超过 2 秒。不知道是我的实现问题还是gprs方面的问题。
服务器监听:
tcpListener = new TcpListener(IPAddress.Any, Names.comPort);
tcpListener.Server.NoDelay = true;
while (true)
{
TcpClient client = tcpListener.AcceptTcpClient();
Thread th = new Thread(new ParameterizedThreadStart(HandleComm));
th.IsBackground = true;
th.start(client);
}
开始接收数据:
HandleComm(object client)
{
NetworkStream clientStream = ((TcpClient)client).GetStream();
while (true)
{
try { bytesRead = clientStream.Read(buffer, 0, 200);}
catch(Exception ex) {break;}
}
}
这是一个简单的实现,我收到第一个数据包的bytesRead的那一刻与第二个数据包相比大约是2s。我认为这太慢了。如何增加接收时间?我已经检查过收到数据并回复后,只花了1毫秒。
添加发送部分:
socket.NoDelay = true;
socket.SendTimeout = 200; // minimum time out
socket.SendBufferSize = bytes.Length;
socket.Send(bytes, SocketFlags.DontRoute);
I am writing a parser in C#. It receives and sends a packet with max length = 100
. However, the time between (receiving and sending) after each packet is more than 2 seconds. I don't know whether it is a problem of my implementation or the gprs side.
Server listening:
tcpListener = new TcpListener(IPAddress.Any, Names.comPort);
tcpListener.Server.NoDelay = true;
while (true)
{
TcpClient client = tcpListener.AcceptTcpClient();
Thread th = new Thread(new ParameterizedThreadStart(HandleComm));
th.IsBackground = true;
th.start(client);
}
Begin receiving data:
HandleComm(object client)
{
NetworkStream clientStream = ((TcpClient)client).GetStream();
while (true)
{
try { bytesRead = clientStream.Read(buffer, 0, 200);}
catch(Exception ex) {break;}
}
}
It is a simple implementation, the moment I receive the bytesRead of the first data packet compared to the second one is about 2s. It is too slow I think. How could I increase receiving time? I already checked after receiving data and replying, it took 1 ms only.
Adding sending part:
socket.NoDelay = true;
socket.SendTimeout = 200; // minimum time out
socket.SendBufferSize = bytes.Length;
socket.Send(bytes, SocketFlags.DontRoute);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论