开放,端口重用
This commit is contained in:
parent
21b02018ee
commit
774983238b
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -62,9 +62,6 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="ProtobufHunterNetCore.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Content Include="protobuf-net.dll" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="app.config" />
|
||||
<None Include="packages.config" />
|
||||
|
@ -346,5 +346,9 @@ namespace HaoYueNet.ClientNetworkNet4x
|
||||
//Console.WriteLine(Msg);
|
||||
OnLogOut(Msg);
|
||||
}
|
||||
public Socket GetClientSocket()
|
||||
{
|
||||
return client;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -156,16 +156,24 @@ namespace HaoYueNet.ServerNetwork
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 启动服务
|
||||
/// </summary>
|
||||
/// <param name="localEndPoint"></param>
|
||||
public bool Start(IPEndPoint localEndPoint)
|
||||
/// <summary>
|
||||
/// 启动服务
|
||||
/// </summary>
|
||||
/// <param name="localEndPoint"></param>
|
||||
/// <param name="bReuseAddress">是否端口重用</param>
|
||||
/// <returns></returns>
|
||||
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);
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user