Home > other >  Novice only 200 points, a great god answer c # LAN communication problems.
Novice only 200 points, a great god answer c # LAN communication problems.

Time:09-30

I use c # write a mobile terminal LAN communication program, the sending delay problems, a great god for help to reassure:

My TcpClient related is defined as:
TcpClient TcpClient=new TcpClient ()
{
ReceiveBufferSize=4096,
ReceiveTimeout=0,
SendBufferSize=4096,
SendTimeout=0,
NoDelay=true
};

Then sending method is as follows:

Public void SendTcpMessage (string MSG)
{
NetworkStream stream=tcpClient. GetStream ();
If (stream. CanWrite)
{
Byte [] bytes=Encoding. UTF8. GetBytes (MSG);

Profile. The Begin (the Send time consuming "");
Stream. BeginWrite (0 bytes, bytes. The Length, OnSendCallback, stream).
}
}

Void OnSendCallback IAsyncResult (ar)
{
Profile. The End (the Send time consuming "");

NetworkStream stream=(NetworkStream) ar. AsyncState;
Stream. EndWrite (ar);
}

First it under my present real machine test:
To invoke SendTcpMessage frequency of 20 times every second, and each sends data size is 12 bytes,
1, with 15 years of OPPO R7 test, send will take in 1 ms to 20000 ms (20 s), very card, if the frequency of once per second, can send time-consuming basic stability between 1 to 4 ms ms, occasionally to a few seconds of time consuming,
2, with 17 years of huawei honor V9 test, basic within 2 ms send time-consuming, occasional fluctuations to a few seconds delay, better than test 1,

Is excuse me I send the frequency is too high or set has a problem, lead to instability in the local area network (LAN), (wifi condition such as area is stable and fluent)



  • Related