开发者

delay of receiving data from a gprs connection

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 sec开发者_如何学Goond 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);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜