feat: udpServer使用异步处理数据包
This commit is contained in:
parent
0350ce8829
commit
b913f58f13
|
@ -287,21 +287,23 @@ public class UDPServer
|
||||||
var remoteEP = new IPEndPoint(IPAddress.Any, listenPort);
|
var remoteEP = new IPEndPoint(IPAddress.Any, listenPort);
|
||||||
byte[] bytes = listener.EndReceive(res, ref remoteEP);
|
byte[] bytes = listener.EndReceive(res, ref remoteEP);
|
||||||
|
|
||||||
|
// 提前开始接收下一个包
|
||||||
|
listener.BeginReceive(new AsyncCallback(ReceiveHandler), null);
|
||||||
|
|
||||||
// Handle RemoteEP
|
// Handle RemoteEP
|
||||||
if (remoteEP is null)
|
if (remoteEP is null)
|
||||||
{
|
{
|
||||||
// logger.Debug($"Receive Data from Unknown at {DateTime.Now.ToString()}:");
|
logger.Debug($"Receive Data from Unknown at {DateTime.Now.ToString()}:");
|
||||||
// logger.Debug($" Original Data : {BitConverter.ToString(bytes).Replace("-", " ")}");
|
logger.Debug($" Original Data : {BitConverter.ToString(bytes).Replace("-", " ")}");
|
||||||
goto BEGIN_RECEIVE;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 异步处理数据包
|
||||||
// Handle Package
|
Task.Run(() =>
|
||||||
|
{
|
||||||
var udpData = RecordUDPData(bytes, remoteEP, Convert.ToInt32(bytes[1]));
|
var udpData = RecordUDPData(bytes, remoteEP, Convert.ToInt32(bytes[1]));
|
||||||
PrintData(udpData);
|
PrintData(udpData);
|
||||||
|
});
|
||||||
BEGIN_RECEIVE:
|
|
||||||
listener.BeginReceive(new AsyncCallback(ReceiveHandler), null);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool SendBytes(IPEndPoint endPoint, byte[] buf)
|
private bool SendBytes(IPEndPoint endPoint, byte[] buf)
|
||||||
|
|
Loading…
Reference in New Issue