本文整理汇总了C#中IHost.NextConnectionID方法的典型用法代码示例。如果您正苦于以下问题:C# IHost.NextConnectionID方法的具体用法?C# IHost.NextConnectionID怎么用?C# IHost.NextConnectionID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IHost
的用法示例。
在下文中一共展示了IHost.NextConnectionID方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BeginConnect
/// <summary>
/// begin connect
/// </summary>
/// <param name="endPoint"></param>
/// <param name="host"></param>
/// <param name="callback"></param>
/// <exception cref="ArgumentNullException">endPoint is null</exception>
/// <exception cref="ArgumentNullException">host is null</exception>
/// <exception cref="ArgumentNullException">callback is null</exception>
public static void BeginConnect(EndPoint endPoint, IHost host, Action<IConnection> callback)
{
if (endPoint == null) throw new ArgumentNullException("endPoint");
if (host == null) throw new ArgumentNullException("host");
if (callback == null) throw new ArgumentNullException("callback");
Log.Trace.Debug(string.Concat("begin connect to ", endPoint.ToString()));
var socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
socket.BeginConnect(endPoint, ar =>
{
try
{
socket.EndConnect(ar);
socket.NoDelay = true;
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
socket.ReceiveBufferSize = host.SocketBufferSize;
socket.SendBufferSize = host.SocketBufferSize;
}
catch (Exception ex)
{
try
{
socket.Close();
socket.Dispose();
}
catch { }
Log.Trace.Error(ex.Message, ex);
callback(null); return;
}
callback(new DefaultConnection(host.NextConnectionID(), socket, host));
}, null);
}
catch (Exception ex)
{
Log.Trace.Error(ex.Message, ex);
callback(null);
}
}