markiodev / Networker

A simple to use TCP and UDP networking library for .NET. Compatible with Unity.
MIT License
477 stars 77 forks source link

UdpClientListener中监听强制使用了127.0.0.1,不适用于多网卡环境 #56

Open qinqoushui opened 4 years ago

qinqoushui commented 4 years ago

在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);
...
}