Networker
Networker copied to clipboard
UdpClientListener中监听强制使用了127.0.0.1,不适用于多网卡环境
在UdpClientListener中
public UdpClientListener(ServerBuilderOptions options,
ILogger<UdpClientListener> logger,
IServerPacketProcessor serverPacketProcessor,
IServerInformation serverInformation)
{
this.options = options;
this.logger = logger;
this.serverPacketProcessor = serverPacketProcessor;
this.serverInformation = serverInformation;
endPointPool = new ObjectPool<EndPoint>(this.options.UdpSocketObjectPoolSize);
for (var i = 0; i < endPointPool.Capacity; i++)
//endPointPool.Push(new IPEndPoint(IPAddress.Loopback, this.options.UdpPort));
endPointPool.Push(new IPEndPoint(BindIPAddress, this.options.UdpPort));
}
public void Listen()
{
client = new UdpClient();
client.ExclusiveAddressUse = false;
client.Client.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
//临时处理,后续使用option传入网卡地址
//endPoint = new IPEndPoint(IPAddress.Loopback, options.UdpPort);
endPoint = new IPEndPoint(BindIPAddress, options.UdpPort);
client.Client.Bind(endPoint);
...
}