本文整理汇总了C#中IClient.Dispose方法的典型用法代码示例。如果您正苦于以下问题:C# IClient.Dispose方法的具体用法?C# IClient.Dispose怎么用?C# IClient.Dispose使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IClient
的用法示例。
在下文中一共展示了IClient.Dispose方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DisconnectClient
/// <summary>
/// Disconnects and removes a client.
/// <seealso cref="ServerBase.Stop"/>
/// <seealso cref="ServerBase.RemoveAllClients"/>
/// </summary>
/// <param name="client">The client to be disconnected/removed</param>
/// <param name="forced">Flag indicating if the client was disconnected already</param>
public void DisconnectClient(IClient client, bool forced)
{
RemoveClient(client);
try
{
OnClientDisconnected(client, forced);
client.Dispose();
}
catch (ObjectDisposedException)
{
// Connection was already closed (probably by the remote side)
}
catch (Exception e)
{
LogManager.GetLogger(CellDef.CORE_LOG_FNAME).ErrorException("Could not disconnect client", e);
}
}
示例2: OnClientDisconnected
/// <summary>
/// Called when a client has been disconnected from the server.
/// </summary>
/// <param name="client">The client that has been disconnected.</param>
/// <param name="forced">Indicates if the client disconnection was forced</param>
protected virtual void OnClientDisconnected(IClient client, bool forced)
{
Info(client, Resources.ClientDisconnected);
ClientDisconnectedHandler handler = ClientDisconnected;
if (handler != null)
handler(client, forced);
client.Dispose();
}
示例3: Main
static void Main(string[] args)
{
if (args.Length < 3)
{
ShowHelp();
return;
}
string protocol = args[0].ToUpper();
string connectionString, fileName;
string networkInterface = "0.0.0.0";
switch (protocol)
{
case "TCP":
if (args.Length > 3)
networkInterface = args[3];
connectionString = string.Format("protocol=TCP; server={0}; interface={1}", args[1], networkInterface);
fileName = FilePath.GetAbsolutePath(args[2]);
break;
case "UDP":
if (args.Length > 3)
networkInterface = args[3];
connectionString = string.Format("protocol=UDP; port={0}; interface={1}", args[1], networkInterface);
fileName = FilePath.GetAbsolutePath(args[2]);
break;
case "MULTICAST":
if (args.Length < 5)
{
ShowHelp();
return;
}
if (args.Length > 5)
networkInterface = args[5];
connectionString = string.Compare(args[3], "ANY", true) == 0 ?
string.Format("protocol=UDP; port={0}; server={1}; interface={2}", args[1], args[2], networkInterface) :
string.Format("protocol=UDP; port={0}; server={1}; multicastSource={2}; interface={3}", args[1], args[2], args[3], networkInterface);
fileName = FilePath.GetAbsolutePath(args[4]);
break;
default:
ShowHelp();
return;
}
Console.WriteLine("\r\nCapturing {0} stream \"{1}\" to file \"{2}\"...\r\n\r\nPress any key to complete capture...\r\n", protocol, connectionString, fileName);
stream = File.Create(fileName);
socket = ClientBase.Create(connectionString);
socket.MaxConnectionAttempts = -1;
socket.ConnectionAttempt += socket_ConnectionAttempt;
socket.ConnectionEstablished += socket_ConnectionEstablished;
socket.ConnectionException += socket_ConnectionException;
socket.ConnectionTerminated += socket_ConnectionTerminated;
socket.ReceiveData += socket_ReceiveData;
socket.ReceiveDataException += socket_ReceiveDataException;
socket.ConnectAsync();
Console.ReadKey();
socket.Dispose();
socket.ConnectionAttempt -= socket_ConnectionAttempt;
socket.ConnectionEstablished -= socket_ConnectionEstablished;
socket.ConnectionException -= socket_ConnectionException;
socket.ConnectionTerminated -= socket_ConnectionTerminated;
socket.ReceiveData -= socket_ReceiveData;
socket.ReceiveDataException -= socket_ReceiveDataException;
stream.Close();
}