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


C# Socket.SetKeepAlive方法代码示例

本文整理汇总了C#中Socket.SetKeepAlive方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.SetKeepAlive方法的具体用法?C# Socket.SetKeepAlive怎么用?C# Socket.SetKeepAlive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Socket的用法示例。


在下文中一共展示了Socket.SetKeepAlive方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CreateSocket

 /// <summary>
 /// 创建一个 <see cref="Socket"/>。
 /// </summary>
 /// <returns><see cref="Socket"/>。</returns>
 public Socket CreateSocket()
 {
     var socket = new Socket(this._EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
     socket.NoDelay = true;
     //socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
     //socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, false);
     if(this._KeepAliveMilliseconds > 0U)
     {
         socket.SetKeepAlive(this._KeepAliveMilliseconds);
     }
     return socket;
 }
开发者ID:supuy-ruby,项目名称:Aoite,代码行数:16,代码来源:SocketInfo.cs

示例2: Connect

		public virtual void Connect()
		{
			try
			{
				IPAddress = GetIPAddress(_dataSource, AddressFamily.InterNetwork);
				IPEndPoint endPoint = new IPEndPoint(IPAddress, _portNumber);

				_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

				// Set Receive Buffer size.
				_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, _packetSize);
				// Set Send	Buffer size.
				_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendBuffer, _packetSize);
				// Disables	the	Nagle algorithm	for	send coalescing.
				_socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);
				// Start sending keepalive packets every 30min after 30min of idle connection
				_socket.SetKeepAlive(KeepAliveTime, KeepAliveInterval);

				// Make	the	socket to connect to the Server
				_socket.Connect(endPoint);
				_networkStream = new NetworkStream(_socket, true);
			}
			catch (SocketException ex)
			{
				throw IscException.ForTypeErrorCodeStrParam(IscCodes.isc_arg_gds, IscCodes.isc_network_error, _dataSource, ex);
			}
		}
开发者ID:fishcodelib,项目名称:FirebirdSql.Data.FirebirdClient,代码行数:27,代码来源:GdsConnection.cs


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