本文整理汇总了C#中ConnectionInfo.ResetConnectionInfo方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionInfo.ResetConnectionInfo方法的具体用法?C# ConnectionInfo.ResetConnectionInfo怎么用?C# ConnectionInfo.ResetConnectionInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConnectionInfo
的用法示例。
在下文中一共展示了ConnectionInfo.ResetConnectionInfo方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetConnection
/// <summary>
/// Internal <see cref="TCPConnection"/> creation which hides the necessary internal calls
/// </summary>
/// <param name="connectionInfo">ConnectionInfo to be used to create connection</param>
/// <param name="defaultSendReceiveOptions">Connection default SendReceiveOptions</param>
/// <param name="tcpClient">If this is an incoming connection we will already have access to the tcpClient, otherwise use null</param>
/// <param name="establishIfRequired">Establish during create if true</param>
/// <param name="sslOptions">SSL options that will be used with this connection.</param>
/// <returns>An existing connection or a new one</returns>
internal static TCPConnection GetConnection(ConnectionInfo connectionInfo, SendReceiveOptions defaultSendReceiveOptions, TcpClient tcpClient, bool establishIfRequired, SSLOptions sslOptions = null)
#endif
{
connectionInfo.ConnectionType = ConnectionType.TCP;
//If we have a tcpClient at this stage we must be server side
#if WINDOWS_PHONE || NETFX_CORE
if (socket != null) connectionInfo.ServerSide = true;
#else
if (tcpClient != null) connectionInfo.ServerSide = true;
if (sslOptions == null) sslOptions = new SSLOptions();
#endif
//Set default connection options if none have been provided
if (defaultSendReceiveOptions == null) defaultSendReceiveOptions = NetworkComms.DefaultSendReceiveOptions;
bool newConnection = false;
TCPConnection connection;
lock (NetworkComms.globalDictAndDelegateLocker)
{
List<Connection> existingConnections = NetworkComms.GetExistingConnection(connectionInfo.RemoteIPEndPoint, connectionInfo.LocalIPEndPoint, connectionInfo.ConnectionType, connectionInfo.ApplicationLayerProtocol);
//Check to see if a connection already exists, if it does return that connection, if not return a new one
if (existingConnections.Count > 0)
{
if (NetworkComms.LoggingEnabled)
NetworkComms.Logger.Trace("Attempted to create new TCPConnection to connectionInfo='" + connectionInfo + "' but there is an existing connection. Existing connection will be returned instead.");
establishIfRequired = false;
connection = (TCPConnection)existingConnections[0];
}
else
{
if (NetworkComms.LoggingEnabled)
NetworkComms.Logger.Trace("Creating new TCPConnection to connectionInfo='" + connectionInfo + "'." + (establishIfRequired ? " Connection will be established." : " Connection will not be established."));
if (connectionInfo.ConnectionState == ConnectionState.Establishing)
throw new ConnectionSetupException("Connection state for connection " + connectionInfo + " is marked as establishing. This should only be the case here due to a bug.");
//If an existing connection does not exist but the info we are using suggests it should we need to reset the info
//so that it can be reused correctly. This case generally happens when using Comms in the format
//TCPConnection.GetConnection(info).SendObject(packetType, objToSend);
if (connectionInfo.ConnectionState == ConnectionState.Established || connectionInfo.ConnectionState == ConnectionState.Shutdown)
connectionInfo.ResetConnectionInfo();
//We add a reference to networkComms for this connection within the constructor
#if WINDOWS_PHONE || NETFX_CORE
connection = new TCPConnection(connectionInfo, defaultSendReceiveOptions, socket);
#else
connection = new TCPConnection(connectionInfo, defaultSendReceiveOptions, tcpClient, sslOptions);
#endif
newConnection = true;
}
}
if (newConnection && establishIfRequired) connection.EstablishConnection();
else if (!newConnection) connection.WaitForConnectionEstablish(NetworkComms.ConnectionEstablishTimeoutMS);
if (!NetworkComms.commsShutdown) TriggerConnectionKeepAliveThread();
return connection;
}