• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Sockets.LingerOption类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中System.Net.Sockets.LingerOption的典型用法代码示例。如果您正苦于以下问题:C# LingerOption类的具体用法?C# LingerOption怎么用?C# LingerOption使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



LingerOption类属于System.Net.Sockets命名空间,在下文中一共展示了LingerOption类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AsyncWebSocketClientConfiguration

        public AsyncWebSocketClientConfiguration()
        {
            InitialBufferAllocationCount = 4;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            SslTargetHost = null;
            SslClientCertificates = new X509CertificateCollection();
            SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
            SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
            SslCheckCertificateRevocation = false;
            SslPolicyErrorsBypassed = false;

            ConnectTimeout = TimeSpan.FromSeconds(10);
            CloseTimeout = TimeSpan.FromSeconds(5);
            KeepAliveInterval = TimeSpan.FromSeconds(30);
            KeepAliveTimeout = TimeSpan.FromSeconds(5);
            ReasonableFragmentSize = 4096;

            EnabledExtensions = new Dictionary<string, IWebSocketExtensionNegotiator>()
            {
                { PerMessageCompressionExtension.RegisteredToken, new PerMessageCompressionExtensionNegotiator() },
            };
            EnabledSubProtocols = new Dictionary<string, IWebSocketSubProtocolNegotiator>();

            OfferedExtensions = new List<WebSocketExtensionOfferDescription>()
            {
                new WebSocketExtensionOfferDescription(PerMessageCompressionExtension.RegisteredToken),
            };
            RequestedSubProtocols = new List<WebSocketSubProtocolRequestDescription>();
        }
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:35,代码来源:AsyncWebSocketClientConfiguration.cs


示例2: SyncSocClient

        public SyncSocClient(string _ipAddress, int port, int timeout)
        {

            try
            {
                IPAddress ipAddress = System.Net.IPAddress.Parse(_ipAddress);
                mPort = port;
                remoteEP = new IPEndPoint(ipAddress, mPort);

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

                if (timeout > 0)
                {
                    mSender.ReceiveTimeout = timeout;
                    mSender.SendTimeout = timeout;
                }
                //mSender.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, timeout);

                // The socket will linger for 10 seconds after Socket.Close is called.
                LingerOption lingerOption = new LingerOption(true, 10);

                mSender.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);

                stateObj = new StateObject(mSender);
            }
            catch (Exception e)
            {
                SetErrorMessage(e, string.Format("소켓생성Error ip[{0}]/port[{1}]/timeout[{2}]]",_ipAddress,port,timeout));
                Logger.error(e.ToString());
            }
        }
开发者ID:WeDoCrm,项目名称:WeDoServer2.0,代码行数:32,代码来源:SocketClient.cs


示例3: AsyncWebSocketServerConfiguration

        public AsyncWebSocketServerConfiguration()
        {
            InitialBufferAllocationCount = 100;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            PendingConnectionBacklog = 200;
            AllowNatTraversal = true;

            SslEnabled = false;
            SslServerCertificate = null;
            SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
            SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
            SslClientCertificateRequired = true;
            SslCheckCertificateRevocation = false;
            SslPolicyErrorsBypassed = false;

            ConnectTimeout = TimeSpan.FromSeconds(10);
            CloseTimeout = TimeSpan.FromSeconds(5);
            KeepAliveInterval = TimeSpan.FromSeconds(60);
            KeepAliveTimeout = TimeSpan.FromSeconds(15);
            ReasonableFragmentSize = 4096;

            EnabledExtensions = new Dictionary<string, IWebSocketExtensionNegotiator>()
            {
                { PerMessageCompressionExtension.RegisteredToken, new PerMessageCompressionExtensionNegotiator() },
            };
            EnabledSubProtocols = new Dictionary<string, IWebSocketSubProtocolNegotiator>();
        }
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:33,代码来源:AsyncWebSocketServerConfiguration.cs


示例4: CloseSocket

		/// <summary>
		/// Close socket channel.
		/// </summary>
		/// <param name="shutdown">Pass true to gracefully close the connection.</param>
		private void CloseSocket(bool shutdown)
		{
			try
			{
				if (this.clientSocket != null)
				{
					if (shutdown)
					{
						this.clientSocket.Shutdown(SocketShutdown.Both);
					}
					else
					{
						LingerOption option = new LingerOption(true, 0);
						this.clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, option);
					}
					this.clientSocket.Close();
				}
			}
			catch (Exception error)
			{
				this.btService.ReportNestedError(error);
			}
			finally
			{
				this.clientSocket = null;
			}
		}
开发者ID:jinby,项目名称:BugTrap,代码行数:31,代码来源:SocketState.cs


示例5: NewSocket

        public static Socket NewSocket()
        {
            LingerOption lo = new LingerOption(true, 10);
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            socket.NoDelay = true;
            socket.LingerState = lo;
            socket.ReceiveBufferSize = Const.BufferSize;
            socket.SendBufferSize = Const.BufferSize;

            return socket;
        }
开发者ID:AndreyAyres,项目名称:AsyncClientServer,代码行数:11,代码来源:Helper.cs


示例6: ClientManager

        private Thread wThread; // The local thread

        #endregion Fields

        #region Constructors

        public ClientManager(Socket clsock)
        {
            this.ClientSocket = clsock;
            this.remoteAddress = RemoteAddress.Parse(clsock.RemoteEndPoint.ToString());
            LingerOption lingeroption = new LingerOption(false, 0);
            this.ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, (Server.cfg.CTI_CLIENT_KEEPALIVE  * 1000));
            this.ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingeroption);
            this.ClientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, (Server.cfg.CTI_CLIENT_TIMEOUT * 1000));

            Server.logger.WriteLine(LogType.Notice, string.Format("ClientManager initialized for {0}",clsock.RemoteEndPoint.ToString()));
        }
开发者ID:happy-star,项目名称:asterisk-cti,代码行数:17,代码来源:ClientManager.cs


示例7: TcpSocketSaeaClientConfiguration

        public TcpSocketSaeaClientConfiguration()
        {
            InitialBufferAllocationCount = 4;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            FrameBuilder = new SizePrefixedFrameBuilder();
        }
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:12,代码来源:TcpSocketSaeaClientConfiguration.cs


示例8: Connect

 /**
  * 连接指定地址
  */
 public void Connect(string ip,int port)
 {
     this.status = STATUS_CONNECTING;
     this.ip = ip;
     this.port = port;
     clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.NoDelay, true);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, 3000);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 3000);
     LingerOption linger = new LingerOption(true,0);
     clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, linger);
     clientSocket.BeginConnect(this.ip, this.port, connected, this);
 }
开发者ID:zhoufannba,项目名称:cocosocket,代码行数:17,代码来源:USocket.cs


示例9: HttpConnectionHandler

        private HttpConnectionHandler(Socket socket, RequestHandler httpProcessor)
        {
            this._socket = socket;
            //
            {
                LingerOption linger = new LingerOption(true, 60);
                _socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, linger);
                // Object langer = _socket.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger);
            }
            _httpProcessor = httpProcessor;

            _networkStream = new NetworkStream(_socket, FileAccess.ReadWrite, false);

        }
开发者ID:rlong,项目名称:dotnet.lib.HttpLibrary,代码行数:14,代码来源:HttpConnectionHandler.cs


示例10: TcpSocketSaeaServerConfiguration

        public TcpSocketSaeaServerConfiguration()
        {
            InitialBufferAllocationCount = 100;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            PendingConnectionBacklog = 200;
            AllowNatTraversal = true;

            FrameBuilder = new SizePrefixedFrameBuilder();
        }
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:15,代码来源:TcpSocketSaeaServerConfiguration.cs


示例11: TcpTransport

		public TcpTransport(Socket socket)
		{
			// parameters validation
			if (socket == null)
				throw new ArgumentNullException("socket");
			if ((socket.AddressFamily != AddressFamily.InterNetwork) || socket.ProtocolType != ProtocolType.Tcp)
				throw new NotSupportedException("Only TCP connections supported");

			_socket = socket;

			// disable nagle delays
			_socket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, 1);

			// set linger option
			LingerOption lingerOption = new LingerOption(true, 3);
			socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, lingerOption);
		}
开发者ID:Orvid,项目名称:NAntUniversalTasks,代码行数:17,代码来源:TcpTransport.cs


示例12: InitializeConnection

        public void InitializeConnection()
        {
            isInitialized = false;
            isClosed = true;

            receivingInit();
            sendingInit();

            errorMessage = "";

            try
            {
                clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

                // Get the remote IP address
                IPAddress ip = IPAddress.Parse(this.ipAddress);
                // Create the end point
                IPEndPoint ipEnd = new IPEndPoint(ip, this.port);
                // Connect to the remote host
                clientSocket.Connect(ipEnd);
                clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
                clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
                clientSocket.SetSocketOption(SocketOptionLevel.Tcp, SocketOptionName.NoDelay, true);

                // http://msdn.microsoft.com/en-us/library/system.net.sockets.lingeroption(VS.71).aspx
                LingerOption myOpts = new LingerOption(true, 2);
                clientSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Linger, myOpts);

                if (clientSocket.Connected)
                {
                    isInitialized = true;
                }
            }
            catch (SocketException e)
            {
                isInitialized = false;
                DebuggerIX.WriteLine(DebuggerTag.Net, "[ClientInitConnection]", "Connection failed, is the server running? " + e.Message);
                errorMessage = e.Message;
            }
            catch (NullReferenceException e)
            {
                isInitialized = false;
                DebuggerIX.WriteLine(DebuggerTag.Net, "[ClientInitConnection]", "Connection failed, is the server running? " + e.Message);
                errorMessage = e.Message;
            }
        }
开发者ID:MartyIX,项目名称:SoTh,代码行数:46,代码来源:TcpClient.cs


示例13: OpenConnection

 // public methods
 public void OpenConnection()
 {
     try
     {
         reqClient = new TcpClient();
         reqClient.NoDelay = false;
         reqClient.ReceiveTimeout = 2000;
         reqClient.SendTimeout = 2000;
         LingerOption lingerOption = new LingerOption(true, 0);
         reqClient.LingerState = lingerOption;
         reqClient.Connect(Connection.BravaIP, Connection.BravaPort);
         Connection.rqStream = reqClient.GetStream();
     }
     catch (SocketException se)
     {
         throw(se);
     }
 }
开发者ID:s9703830,项目名称:SmartVillage,代码行数:19,代码来源:BravaSocket.cs


示例14: AsyncTcpSocketClientConfiguration

        public AsyncTcpSocketClientConfiguration()
        {
            InitialBufferAllocationCount = 4;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            SslEnabled = false;
            SslTargetHost = null;
            SslClientCertificates = new X509CertificateCollection();
            SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
            SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
            SslCheckCertificateRevocation = false;
            SslPolicyErrorsBypassed = false;

            ConnectTimeout = TimeSpan.FromSeconds(15);
            FrameBuilder = new SizePrefixedFrameBuilder();
        }
开发者ID:xiaomiwk,项目名称:Cowboy,代码行数:21,代码来源:AsyncTcpSocketClientConfiguration.cs


示例15: WebSocketClientConfiguration

        public WebSocketClientConfiguration()
        {
            InitialPooledBufferCount = 4;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            SslTargetHost = null;
            SslClientCertificates = new X509CertificateCollection();
            SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
            SslCheckCertificateRevocation = false;
            SslPolicyErrorsBypassed = false;

            ConnectTimeout = TimeSpan.FromSeconds(10);
            CloseTimeout = TimeSpan.FromSeconds(5);
            KeepAliveInterval = TimeSpan.FromSeconds(30);
            KeepAliveTimeout = TimeSpan.FromSeconds(5);
            ReasonableFragmentSize = 4096;
        }
开发者ID:cube3power,项目名称:Cowboy,代码行数:22,代码来源:WebSocketClientConfiguration.cs


示例16: TcpSocketServerConfiguration

        public TcpSocketServerConfiguration()
        {
            InitialPooledBufferCount = 100;
            ReceiveBufferSize = 8192;
            SendBufferSize = 8192;
            ReceiveTimeout = TimeSpan.Zero;
            SendTimeout = TimeSpan.Zero;
            NoDelay = true;
            LingerState = new LingerOption(false, 0); // The socket will linger for x seconds after Socket.Close is called.

            PendingConnectionBacklog = 200;
            AllowNatTraversal = true;

            SslEnabled = false;
            SslServerCertificate = null;
            SslEncryptionPolicy = EncryptionPolicy.RequireEncryption;
            SslEnabledProtocols = SslProtocols.Ssl3 | SslProtocols.Tls;
            SslClientCertificateRequired = true;
            SslCheckCertificateRevocation = false;
            SslPolicyErrorsBypassed = false;

            ConnectTimeout = TimeSpan.FromSeconds(15);
            FrameBuilder = new LengthPrefixedFrameBuilder();
        }
开发者ID:cube3power,项目名称:Cowboy,代码行数:24,代码来源:TcpSocketServerConfiguration.cs


示例17: GetConnection

        // --------------- Helper methods ------------------------------------
        private NetworkStream GetConnection()
        {
            try
            {
                if (host == null)
                { host = SmtpConfig.SmtpHost; }

                if (port == 0)
                { port = SmtpConfig.SmtpPort; }

                if (host != null && port != 0)
                {
                    tcpc = new TcpClient(host, port);

                    LogMessage("connecting to:" + host + ":" + port, "");
                    tcpc.ReceiveTimeout= recieveTimeout;
                    tcpc.SendTimeout = sendTimeout;
                    tcpc.ReceiveBufferSize = receiveBufferSize;
                    tcpc.SendBufferSize = sendBufferSize;

                    LingerOption lingerOption = new LingerOption(true, 10);
                    tcpc.LingerState = lingerOption;

                }
                else
                {
                    throw new SmtpException("Cannot use SendMail() method without specifying target host and port");
                }
            }
            catch(SocketException e)
            {
                throw new SmtpException("Cannot connect to specified smtp host(" + host + ":" + port + ").", e);
            }

            OnConnect(EventArgs.Empty);
            return tcpc.GetStream();
        }
开发者ID:htawab,项目名称:wiscms,代码行数:38,代码来源:Smtp.cs


示例18: GetLingerOption

        public static unsafe SocketError GetLingerOption(SafeCloseSocket handle, out LingerOption optionValue)
        {
            var opt = new Interop.Sys.LingerOption();
            Interop.Error err = Interop.Sys.GetLingerOption(handle.FileDescriptor, &opt);
            if (err != Interop.Error.SUCCESS)
            {
                optionValue = default(LingerOption);
                return GetSocketErrorForErrorCode(err);
            }

            optionValue = new LingerOption(opt.OnOff != 0, opt.Seconds);
            return SocketError.Success;
        }
开发者ID:jemmy655,项目名称:corefx,代码行数:13,代码来源:SocketPal.Unix.cs


示例19: SetLingerOption

        public static unsafe SocketError SetLingerOption(SafeCloseSocket handle, LingerOption optionValue)
        {
            var opt = new Interop.Sys.LingerOption {
                OnOff = optionValue.Enabled ? 1 : 0,
                Seconds = optionValue.LingerTime
            };

            Interop.Error err = Interop.Sys.SetLingerOption(handle.FileDescriptor, &opt);
            return err == Interop.Error.SUCCESS ? SocketError.Success : GetSocketErrorForErrorCode(err);
        }
开发者ID:jemmy655,项目名称:corefx,代码行数:10,代码来源:SocketPal.Unix.cs


示例20: GetLingerOption

        public static SocketError GetLingerOption(SafeCloseSocket handle, out LingerOption optionValue)
        {
            Interop.Winsock.Linger lngopt = new Interop.Winsock.Linger();
            int optlen = 4;

            // This can throw ObjectDisposedException.
            SocketError errorCode = Interop.Winsock.getsockopt(
                handle,
                SocketOptionLevel.Socket,
                SocketOptionName.Linger,
                out lngopt,
                ref optlen);

            if (errorCode == SocketError.SocketError)
            {
                optionValue = default(LingerOption);
                return GetLastSocketError();
            }

            optionValue = new LingerOption(lngopt.OnOff != 0, (int)lngopt.Time);
            return SocketError.Success;
        }
开发者ID:vbouret,项目名称:corefx,代码行数:22,代码来源:SocketPal.Windows.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Sockets.MulticastOption类代码示例发布时间:2022-05-26
下一篇:
C# Sockets.IPv6MulticastOption类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap