本文整理汇总了C#中ITcpChannel.Close方法的典型用法代码示例。如果您正苦于以下问题:C# ITcpChannel.Close方法的具体用法?C# ITcpChannel.Close怎么用?C# ITcpChannel.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITcpChannel
的用法示例。
在下文中一共展示了ITcpChannel.Close方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteConnectModules
private async Task ExecuteConnectModules(ITcpChannel channel, IClientContext context)
{
var result = ModuleResult.Continue;
for (var i = 0; i < _modules.Length; i++)
{
var connectMod = _modules[i] as IConnectionEvents;
if (connectMod == null)
continue;
try
{
result = await connectMod.OnClientConnected(context);
}
catch (Exception exception)
{
context.Error = exception;
result = ModuleResult.SendResponse;
}
if (result != ModuleResult.Continue)
break;
}
switch (result)
{
case ModuleResult.Disconnect:
channel.Close();
break;
case ModuleResult.SendResponse:
channel.Send(context.ResponseMessage);
break;
}
}
示例2: OnDecoderFailure
private void OnDecoderFailure(ITcpChannel channel, Exception error)
{
var pos = error.Message.IndexOfAny(new[] {'\r', '\n'});
var descr = pos == -1 ? error.Message : error.Message.Substring(0, pos);
var response = new HttpResponseBase(HttpStatusCode.BadRequest, descr, "HTTP/1.1");
channel.Send(response);
channel.Close();
}
示例3: OnDecoderFailure
private void OnDecoderFailure(ITcpChannel channel, Exception error)
{
var pos = error.Message.IndexOfAny(new[] {'\r', '\n'});
var descr = pos == -1 ? error.Message : error.Message.Substring(0, pos);
var response = new HttpResponse(HttpStatusCode.BadRequest, descr, "HTTP/1.1");
var counter = (int)channel.Data.GetOrAdd(HttpMessage.PipelineIndexKey, x => 1);
response.Headers[HttpMessage.PipelineIndexKey] = counter.ToString();
channel.Send(response);
channel.Close();
}
示例4: ExecuteModules
private async Task ExecuteModules(ITcpChannel channel, ClientContext context)
{
var result = ModuleResult.Continue;
for (var i = 0; i < _modules.Length; i++)
{
try
{
await _modules[i].BeginRequestAsync(context);
}
catch (Exception exception)
{
context.Error = exception;
result = ModuleResult.SendResponse;
}
}
if (result == ModuleResult.Continue)
{
for (var i = 0; i < _modules.Length; i++)
{
try
{
result = await _modules[i].ProcessAsync(context);
}
catch (Exception exception)
{
context.Error = exception;
result = ModuleResult.SendResponse;
}
if (result != ModuleResult.Continue)
break;
}
}
try
{
await EndRequestAsync(context);
}
catch (Exception exception)
{
if (context.ResponseMessage == null)
context.ResponseMessage = exception;
result = ModuleResult.Disconnect;
}
if (context.ResponseMessage != null)
channel.Send(context.ResponseMessage);
if (result == ModuleResult.Disconnect)
{
channel.Close();
}
}
示例5: OnMessage
/// <summary>
/// Handles the upgrade
/// </summary>
/// <param name="source">Channel that we've received a request from</param>
/// <param name="msg">Message received.</param>
protected override void OnMessage(ITcpChannel source, object msg)
{
var httpMessage = msg as IHttpMessage;
if (WebSocketUtils.IsWebSocketUpgrade(httpMessage))
{
if (httpMessage is IHttpRequest) // server mode
{
var args = new WebSocketClientConnectEventArgs(source, (IHttpRequest) httpMessage);
WebSocketClientConnect(this, args);
if (args.MayConnect)
{
var webSocketKey = httpMessage.Headers["Sec-WebSocket-Key"];
// TODO: why not provide the response in the WebSocketClientConnectEventArgs event?
var response = new WebSocketUpgradeResponse(webSocketKey);
source.Send(response);
WebSocketClientConnected(this,
new WebSocketClientConnectedEventArgs(source, (IHttpRequest) httpMessage, response));
}
else if (args.SendResponse)
{
var response = new HttpResponseBase(HttpStatusCode.NotImplemented, "Not Implemented", "HTTP/1.1");
if (args.Response != null)
response.Body = args.Response;
source.Send(response);
}
return;
}
if (httpMessage is IHttpResponse) // client mode
{
WebSocketClientConnected(this,
new WebSocketClientConnectedEventArgs(source, null, (IHttpResponse) httpMessage));
}
}
var webSocketMessage = msg as IWebSocketMessage;
if (webSocketMessage != null)
{
// standard message responses handled by listener
switch (webSocketMessage.Opcode)
{
case WebSocketOpcode.Ping:
source.Send(new WebSocketMessage(WebSocketOpcode.Pong, webSocketMessage.Payload));
return;
case WebSocketOpcode.Close:
source.Send(new WebSocketMessage(WebSocketOpcode.Close));
source.Close();
WebSocketClientDisconnected(this,
new ClientDisconnectedEventArgs(source, new Exception("WebSocket closed")));
return;
}
_webSocketMessageReceived(source, webSocketMessage);
return;
}
base.OnMessage(source, msg);
}