You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-17 23:56:30 +09:00
Can configure to be dual-mode, or plain IPv4/6
This commit is contained in:
@@ -123,7 +123,7 @@ namespace Lidgren.Network
|
|||||||
mutex.WaitOne();
|
mutex.WaitOne();
|
||||||
|
|
||||||
if (m_socket == null)
|
if (m_socket == null)
|
||||||
m_socket = new Socket(AddressFamily.InterNetworkV6, SocketType.Dgram, ProtocolType.Udp);
|
m_socket = new Socket(m_configuration.LocalAddress.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
|
||||||
|
|
||||||
if (reBind)
|
if (reBind)
|
||||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
|
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, (int)1);
|
||||||
@@ -131,7 +131,9 @@ namespace Lidgren.Network
|
|||||||
m_socket.ReceiveBufferSize = m_configuration.ReceiveBufferSize;
|
m_socket.ReceiveBufferSize = m_configuration.ReceiveBufferSize;
|
||||||
m_socket.SendBufferSize = m_configuration.SendBufferSize;
|
m_socket.SendBufferSize = m_configuration.SendBufferSize;
|
||||||
m_socket.Blocking = false;
|
m_socket.Blocking = false;
|
||||||
m_socket.DualMode = true;
|
|
||||||
|
if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
|
||||||
|
m_socket.DualMode = true;
|
||||||
|
|
||||||
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress.MapToIPv6(), reBind ? m_listenPort : m_configuration.Port);
|
var ep = (EndPoint)new NetEndPoint(m_configuration.LocalAddress.MapToIPv6(), reBind ? m_listenPort : m_configuration.Port);
|
||||||
m_socket.Bind(ep);
|
m_socket.Bind(ep);
|
||||||
|
|||||||
@@ -153,7 +153,7 @@ namespace Lidgren.Network
|
|||||||
targetCopy.Port = target.Port;
|
targetCopy.Port = target.Port;
|
||||||
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
|
||||||
}
|
}
|
||||||
else
|
else if(m_configuration.DualStack && m_configuration.LocalAddress.AddressFamily == AddressFamily.InterNetworkV6)
|
||||||
NetUtility.CopyEndpoint(target, targetCopy); //Maps to IPv6 for Dual Mode
|
NetUtility.CopyEndpoint(target, targetCopy); //Maps to IPv6 for Dual Mode
|
||||||
|
|
||||||
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, targetCopy);
|
int bytesSent = m_socket.SendTo(data, 0, numBytes, SocketFlags.None, targetCopy);
|
||||||
|
|||||||
@@ -303,7 +303,8 @@ namespace Lidgren.Network
|
|||||||
{
|
{
|
||||||
if (remoteEndPoint == null)
|
if (remoteEndPoint == null)
|
||||||
throw new ArgumentNullException("remoteEndPoint");
|
throw new ArgumentNullException("remoteEndPoint");
|
||||||
remoteEndPoint = NetUtility.MapToIPv6(remoteEndPoint);
|
if(m_configuration.DualStack)
|
||||||
|
remoteEndPoint = NetUtility.MapToIPv6(remoteEndPoint);
|
||||||
|
|
||||||
lock (m_connections)
|
lock (m_connections)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -48,6 +48,8 @@ namespace Lidgren.Network
|
|||||||
private string m_networkThreadName;
|
private string m_networkThreadName;
|
||||||
private IPAddress m_localAddress;
|
private IPAddress m_localAddress;
|
||||||
private IPAddress m_broadcastAddress;
|
private IPAddress m_broadcastAddress;
|
||||||
|
private bool m_dualStack;
|
||||||
|
|
||||||
internal bool m_acceptIncomingConnections;
|
internal bool m_acceptIncomingConnections;
|
||||||
internal int m_maximumConnections;
|
internal int m_maximumConnections;
|
||||||
internal int m_defaultOutgoingMessageCapacity;
|
internal int m_defaultOutgoingMessageCapacity;
|
||||||
@@ -341,10 +343,24 @@ namespace Lidgren.Network
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the local broadcast address to use when broadcasting
|
/// Gets or sets a value indicating whether the library should use IPv6 dual stack mode
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public IPAddress BroadcastAddress
|
public bool DualStack
|
||||||
|
{
|
||||||
|
get { return m_dualStack; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (m_isLocked)
|
||||||
|
throw new NetException(c_isLockedMessage);
|
||||||
|
m_dualStack = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Gets or sets the local broadcast address to use when broadcasting
|
||||||
|
/// </summary>
|
||||||
|
public IPAddress BroadcastAddress
|
||||||
{
|
{
|
||||||
get { return m_broadcastAddress; }
|
get { return m_broadcastAddress; }
|
||||||
set
|
set
|
||||||
|
|||||||
Reference in New Issue
Block a user