BindlLocal
parent
add66ce981
commit
065c76af4e
|
|
@ -44,10 +44,24 @@ namespace dotNetty_kcp
|
||||||
|
|
||||||
public System.Threading.Tasks.Task<IChannel> BindLocal()
|
public System.Threading.Tasks.Task<IChannel> BindLocal()
|
||||||
{
|
{
|
||||||
var localAddress = new IPEndPoint(IPAddress.Any, 0);
|
//var localAddress = new IPEndPoint(IPAddress.Any, 0);
|
||||||
|
var localAddress = new IPEndPoint(GetLocalIPAddress(), 0);
|
||||||
return bootstrap.BindAsync(localAddress);
|
return bootstrap.BindAsync(localAddress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static string GetLocalIPAddress()
|
||||||
|
{
|
||||||
|
var host = Dns.GetHostEntry(Dns.GetHostName());
|
||||||
|
foreach (var ip in host.AddressList)
|
||||||
|
{
|
||||||
|
if (ip.AddressFamily == AddressFamily.InterNetwork)
|
||||||
|
{
|
||||||
|
return ip.ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new Exception("No network adapters with an IPv4 address in the system!");
|
||||||
|
}
|
||||||
|
|
||||||
public void init(ChannelConfig channelConfig, ExecutorPool executorPool, IEventLoopGroup eventLoopGroup)
|
public void init(ChannelConfig channelConfig, ExecutorPool executorPool, IEventLoopGroup eventLoopGroup)
|
||||||
{
|
{
|
||||||
if (channelConfig.UseConvChannel)
|
if (channelConfig.UseConvChannel)
|
||||||
|
|
@ -101,7 +115,8 @@ namespace dotNetty_kcp
|
||||||
* 在4G切换为wifi等场景使用
|
* 在4G切换为wifi等场景使用
|
||||||
* @param ukcp
|
* @param ukcp
|
||||||
*/
|
*/
|
||||||
public void reconnect(Ukcp ukcp){
|
public void reconnect(Ukcp ukcp)
|
||||||
|
{
|
||||||
if (!(_channelManager is ServerConvChannelManager))
|
if (!(_channelManager is ServerConvChannelManager))
|
||||||
{
|
{
|
||||||
throw new Exception("reconnect can only be used in convChannel");
|
throw new Exception("reconnect can only be used in convChannel");
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue