本文整理汇总了C#中System.Net.IPEndPoint.GetHashCode方法的典型用法代码示例。如果您正苦于以下问题:C# IPEndPoint.GetHashCode方法的具体用法?C# IPEndPoint.GetHashCode怎么用?C# IPEndPoint.GetHashCode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.IPEndPoint
的用法示例。
在下文中一共展示了IPEndPoint.GetHashCode方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientTransport
public ClientTransport(IPEndPoint ip, int minRpc, int maxRpc, float packetDropRate)
{
_random = new Random(ip.GetHashCode());
_minRpc = minRpc;
_maxRpc = maxRpc;
_packetDropRate = packetDropRate;
}
示例2: ConnectorI
//
// Only for use by EndpointI.
//
internal ConnectorI(Instance instance, string host, IPEndPoint addr, int timeout, string connectionId)
{
_instance = instance;
_host = host;
_logger = instance.communicator().getLogger();
_addr = addr;
_timeout = timeout;
_connectionId = connectionId;
_hashCode = _addr.GetHashCode();
_hashCode = 5 * _hashCode + _timeout;
_hashCode = 5 * _hashCode + _connectionId.GetHashCode();
}
示例3: TcpConnector
//
// Only for use by TcpEndpoint
//
internal TcpConnector(Instance instance, IPEndPoint addr, int timeout, string connectionId)
{
_instance = instance;
_traceLevels = instance.traceLevels();
_logger = instance.initializationData().logger;
_addr = addr;
_timeout = timeout;
_connectionId = connectionId;
_hashCode = _addr.GetHashCode();
_hashCode = 5 * _hashCode + _timeout;
_hashCode = 5 * _hashCode + _connectionId.GetHashCode();
}
示例4: GetAServer
public Server GetAServer(IStrategyCallerType type, IPEndPoint localIPEndPoint)
{
var configs = _controller.GetCurrentConfiguration().configs;
int index;
if (type == IStrategyCallerType.TCP)
{
index = _random.Next();
}
else
{
index = localIPEndPoint.GetHashCode();
}
return configs[index % configs.Count];
}
示例5: UdpConnector
//
// Only for use by TcpEndpoint
//
internal UdpConnector(Instance instance, IPEndPoint addr, string mcastInterface, int mcastTtl,
byte protocolMajor, byte protocolMinor, byte encodingMajor, byte encodingMinor,
string connectionId)
{
instance_ = instance;
_addr = addr;
_mcastInterface = mcastInterface;
_mcastTtl = mcastTtl;
_protocolMajor = protocolMajor;
_protocolMinor = protocolMinor;
_encodingMajor = encodingMajor;
_encodingMinor = encodingMinor;
_connectionId = connectionId;
_hashCode = _addr.GetHashCode();
_hashCode = 5 * _hashCode + _mcastInterface.GetHashCode();
_hashCode = 5 * _hashCode + _mcastTtl.GetHashCode();
_hashCode = 5 * _hashCode + _connectionId.GetHashCode();
}
示例6: NetTest5_IPEndPointBasic
public MFTestResults NetTest5_IPEndPointBasic()
{
/// <summary>
/// 1. Creates 30 Random IPs between 0.0.0.0 and 255.255.255.127
/// 2. Verifies that they can be constructed as IPEndPoints with both ctors
/// 3. Verifies that their data, ToString and GetHashCode funcs return normally
/// 4. Clones one with Create and verifies the above funcs again
/// </summary>
///
bool testResult = true;
try
{
Random random = new Random();
for (int i = 0; i <= 30; i++)
{
int[] IPInts = { random.Next(256), random.Next(256),
random.Next(256), random.Next(128) };
int portInt = random.Next(65535) + 1;
long addressLong = (long)(
IPInts[0]
+ IPInts[1] * 256
+ IPInts[2] * 256 * 256
+ IPInts[3] * 256 * 256 * 256);
Log.Comment("Random IP " + IPInts[0] + "." + IPInts[1]
+ "." + IPInts[2] + "." + IPInts[3] + ":" + portInt);
IPAddress address = new IPAddress(addressLong);
Log.Comment("EndPoint1 created with IPAddress and int");
IPEndPoint endPoint1 = new IPEndPoint(address,portInt);
Log.Comment("EndPoint2 created with long and int");
IPEndPoint endPoint2 = new IPEndPoint(addressLong, portInt);
if (endPoint1 == null)
throw new Exception("EndPoint1 is null");
if (endPoint2 == null)
throw new Exception("EndPoint2 is null");
Type typeOfEndPoint = endPoint1.GetType();
if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
throw new Exception("EndPoint1 Type is incorrect");
typeOfEndPoint = endPoint2.GetType();
if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
throw new Exception("EndPoint2 Type is incorrect");
if (endPoint1.ToString() != endPoint2.ToString())
throw new Exception("ToString returns differently for same data");
if (!endPoint1.Equals(endPoint2))
{
throw new Exception("Equals returns false for same data");
}
int hashCode1 = endPoint1.GetHashCode();
int hashCode2 = endPoint2.GetHashCode();
if (hashCode1 != hashCode2)
throw new Exception("GetHasCode returns differently for same data");
if (endPoint1.Address.ToString() != endPoint2.Address.ToString()
|| endPoint1.Address.ToString() != address.ToString()
|| endPoint2.Address.ToString() != address.ToString())
throw new Exception("Address returns wrong data");
if (endPoint1.Port != endPoint2.Port
|| endPoint1.Port != portInt
|| endPoint2.Port != portInt)
throw new Exception("Port returns wrong data");
Log.Comment("Cloning Enpoint1 into EndPoint2");
endPoint2 = (IPEndPoint)endPoint2.Create(endPoint1.Serialize());
typeOfEndPoint = endPoint2.GetType();
if (typeOfEndPoint != Type.GetType("System.Net.IPEndPoint"))
throw new Exception("EndPoint2 Type is incorrect after clone");
if (endPoint1.ToString() != endPoint2.ToString())
throw new Exception("ToString returns differently for cloned data");
//21295 GetHashCode returns differently for cloned data
if (endPoint1.GetHashCode() != endPoint2.GetHashCode())
throw new Exception("GetHashCode returns differently for cloned data");
if (endPoint1.Address.ToString() != endPoint2.Address.ToString()
|| endPoint1.Address.ToString() != address.ToString()
|| endPoint2.Address.ToString() != address.ToString())
throw new Exception("Address returns wrong data after clone");
if (endPoint1.Port != endPoint2.Port
|| endPoint1.Port != portInt
|| endPoint2.Port != portInt)
throw new Exception("Port returns wrong data after clone");
Log.Comment("Recreating EndPoint2 with new data");
int portInt2 = portInt % 2 + 1;
long addressLong2 = (long)(
(IPInts[0] % 2 + 1)
+ (IPInts[1] % 2 + 1 )* 256
+ (IPInts[2] % 2 + 1 )* 256 * 256
+ (IPInts[3] % 2 + 1 )* 256 * 256 * 256);
//.........这里部分代码省略.........
示例7: Session
/// <summary>
/// Atheusネットワークへ参加します
/// </summary>
/// <param name="server">ホスト情報</param>
public Session( IPEndPoint server )
: this()
{
TcpClient tcp = new TcpClient( );
tcp.ExclusiveAddressUse = true;
tcp.NoDelay = true;
Socket = tcp.Client;
IPEndPoint = server;
HashCode = IPEndPoint.GetHashCode( ) ^ Thread.GetHashCode( );
Buffer = new byte[ Socket.ReceiveBufferSize ];
Bufferd = new List<byte>( Buffer.Length );
}
示例8: Server
public Server(int volume, IPEndPoint id, Log log, ITransport transport)
{
//_config = config;
Volume = volume;
_id = id;
_random = new Random((int)DateTime.UtcNow.Ticks ^ _id.GetHashCode());
//_dataDir = dataDir;
_currentState = new StoppedState(this);
_transport = transport;
_persistedStore = log;
}
示例9: CeaseHolePunching
/// <summary>
/// Stop any udp hole punching in progress towards ep
/// </summary>
public void CeaseHolePunching(IPEndPoint ep)
{
int hc = ep.GetHashCode();
if (m_holePunches != null)
{
bool wasRemoved = false;
do
{
for (int i = 0; i < m_holePunches.Count; i++)
{
if (m_holePunches[i].GetHashCode() == hc)
{
m_holePunches.RemoveAt(i);
wasRemoved = true;
break;
}
}
} while (m_holePunches.Count > 0 && wasRemoved);
if (m_holePunches.Count == 0)
m_holePunches = null;
}
}
示例10: Write
public void Write(IPEndPoint endpoint, Transports transport)
{
if (transport != Transports.Ws && transport != Transports.Wss)
Write(endpoint);
else
{
Write(C.i);
Write((UInt32)endpoint.GetHashCode());
Write(C._invalid);
}
}
示例11: FindConnection
private NetConnection FindConnection(IPEndPoint endpoint)
{
NetConnection retval;
if (m_connectionsLookUpTable.TryGetValue(endpoint.GetHashCode(), out retval))
return retval;
return null;
/*
for (int i = 0; i < Connections.Length; i++)
{
if (Connections[i] != null && Connections[i].Status != NetConnectionStatus.Disconnected && Connections[i].RemoteEndpoint.Equals(endpoint))
return Connections[i];
}
return null;
*/
}
示例12: AddConnection
internal NetConnection AddConnection(IPEndPoint remoteEndpoint, int remoteClockOffset)
{
// find empty slot
for (int i = 0; i < Connections.Length; i++)
{
if (Connections[i] == null)
{
NetConnection conn = new NetConnection(this, remoteEndpoint);
conn.RemoteClockOffset = remoteClockOffset;
Log.Verbose("Initializing remote clock offset to " + remoteClockOffset + " ms");
conn.m_firstSentHandshake = NetTime.Now;
conn.m_lastSentHandshake = conn.m_firstSentHandshake;
int hash = remoteEndpoint.GetHashCode();
NetConnection existingConn;
if (m_connectionsLookUpTable.TryGetValue(hash, out existingConn))
{
if (existingConn.Status != NetConnectionStatus.Disconnected)
throw new NetException("Ack thphth; Connections lookup hash value taken!");
// disconnected; just remove it
RemoveConnection(existingConn);
}
Connections[i] = conn;
m_connectionsLookUpTable[hash] = conn;
conn.SetStatus(NetConnectionStatus.Connecting, "Connecting from " + remoteEndpoint);
return conn;
}
}
Log.Warning("Failed to add new connection!");
return null;
}
示例13: CeaseHolePunching
/// <summary>
/// Stop any udp hole punching in progress towards ep
/// </summary>
public void CeaseHolePunching(IPEndPoint ep)
{
if (ep == null)
return;
int hc = ep.GetHashCode();
if (m_holePunches != null)
{
for (int i = 0; i < m_holePunches.Count; )
{
if (m_holePunches[i] != null && m_holePunches[i].GetHashCode() == hc)
{
LogVerbose("Ceasing hole punching to " + m_holePunches[i]);
m_holePunches.RemoveAt(i);
}
else
i++;
}
if (m_holePunches.Count < 1)
m_holePunches = null;
}
}