本文整理汇总了C#中System.Net.Sockets.LingerOption类的典型用法代码示例。如果您正苦于以下问题:C# LingerOption类的具体用法?C# LingerOption怎么用?C# LingerOption使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
LingerOption类属于System.Net.Sockets命名空间,在下文中一共展示了LingerOption类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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>();
}
示例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());
}
}
示例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>();
}
示例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;
}
}
示例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;
}
示例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()));
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
示例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;
}
}
示例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);
}
}
示例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();
}
示例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;
}