diff --git a/NetLib/HaoYueNet.ClientNetwork/NetworkHelperCore.cs b/NetLib/HaoYueNet.ClientNetwork/NetworkHelperCore.cs
index 7ae0a6f..849bc52 100644
--- a/NetLib/HaoYueNet.ClientNetwork/NetworkHelperCore.cs
+++ b/NetLib/HaoYueNet.ClientNetwork/NetworkHelperCore.cs
@@ -1,5 +1,6 @@
using Google.Protobuf;
using HunterProtobufCore;
+using System.Net;
using System.Net.Sockets;
namespace HaoYueNet.ClientNetwork
@@ -342,5 +343,10 @@ namespace HaoYueNet.ClientNetwork
//Console.WriteLine(Msg);
OnLogOut(Msg);
}
+
+ public Socket GetClientSocket()
+ {
+ return client;
+ }
}
}
diff --git a/NetLib/HaoYueNet.ClientNetworkNet4x/HaoYueNet.ClientNetworkNet4x.csproj b/NetLib/HaoYueNet.ClientNetworkNet4x/HaoYueNet.ClientNetworkNet4x.csproj
index d0e9994..056b04a 100644
--- a/NetLib/HaoYueNet.ClientNetworkNet4x/HaoYueNet.ClientNetworkNet4x.csproj
+++ b/NetLib/HaoYueNet.ClientNetworkNet4x/HaoYueNet.ClientNetworkNet4x.csproj
@@ -62,9 +62,6 @@
-
-
-
diff --git a/NetLib/HaoYueNet.ClientNetworkNet4x/NetworkHelperCore.cs b/NetLib/HaoYueNet.ClientNetworkNet4x/NetworkHelperCore.cs
index b258f9f..a7caf3e 100644
--- a/NetLib/HaoYueNet.ClientNetworkNet4x/NetworkHelperCore.cs
+++ b/NetLib/HaoYueNet.ClientNetworkNet4x/NetworkHelperCore.cs
@@ -346,5 +346,9 @@ namespace HaoYueNet.ClientNetworkNet4x
//Console.WriteLine(Msg);
OnLogOut(Msg);
}
+ public Socket GetClientSocket()
+ {
+ return client;
+ }
}
}
diff --git a/NetLib/HaoYueNet.ServerNetwork/NetWork/SocketManager.cs b/NetLib/HaoYueNet.ServerNetwork/NetWork/SocketManager.cs
index e0d21dd..55f7a65 100644
--- a/NetLib/HaoYueNet.ServerNetwork/NetWork/SocketManager.cs
+++ b/NetLib/HaoYueNet.ServerNetwork/NetWork/SocketManager.cs
@@ -156,16 +156,24 @@ namespace HaoYueNet.ServerNetwork
}
- ///
- /// 启动服务
- ///
- ///
- public bool Start(IPEndPoint localEndPoint)
+ ///
+ /// 启动服务
+ ///
+ ///
+ /// 是否端口重用
+ ///
+ public bool Start(IPEndPoint localEndPoint,bool bReuseAddress = false)
{
try
{
m_clients.Clear();
listenSocket = new Socket(localEndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+
+ if (bReuseAddress)
+ {
+ listenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
+ }
+
listenSocket.Bind(localEndPoint);
// start the server with a listen backlog of 100 connections
listenSocket.Listen(m_maxConnectNum);
diff --git a/Simple/Client-Cli/Program.cs b/Simple/Client-Cli/Program.cs
index c0dd0de..e89f01a 100644
--- a/Simple/Client-Cli/Program.cs
+++ b/Simple/Client-Cli/Program.cs
@@ -1,5 +1,7 @@
using ClientCore;
using ClientCore.Event;
+using System.Net;
+using System.Net.Sockets;
App.Init("127.0.0.1", 23846);
@@ -31,6 +33,15 @@ while (true)
}
App.chat.SendChatMsg(CmdArr[1]);
break;
+ case "socket":
+ {
+ Socket socket = App.networkHelper.GetClientSocket();
+ if (socket == null)
+ return;
+ IPEndPoint endpoint = ((IPEndPoint)socket.LocalEndPoint);
+ Console.WriteLine($"LocalEndPoint IP->{endpoint.Address.ToString()} Port->{endpoint.Port}");
+ }
+ break;
default:
Console.WriteLine("未知命令" + CommandStr);
break;