当前位置: 首页>>代码示例>>C#>>正文


C# IClient.Dispose方法代码示例

本文整理汇总了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);
			}
		}
开发者ID:WCellFR,项目名称:WCellFR,代码行数:25,代码来源:ServerBase.cs

示例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();
		}
开发者ID:WCellFR,项目名称:WCellFR,代码行数:15,代码来源:ServerBase.cs

示例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();
        }
开发者ID:rmc00,项目名称:gsf,代码行数:76,代码来源:Program.cs


注:本文中的IClient.Dispose方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。