本文整理汇总了C#中ITcpChannel类的典型用法代码示例。如果您正苦于以下问题:C# ITcpChannel类的具体用法?C# ITcpChannel怎么用?C# ITcpChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITcpChannel类属于命名空间,在下文中一共展示了ITcpChannel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Build
/// <summary>
/// Build a new SSL steam.
/// </summary>
/// <param name="channel">Channel which will use the stream</param>
/// <param name="socket">Socket to wrap</param>
/// <returns>Stream which is ready to be used (must have been validated)</returns>
public SslStream Build(ITcpChannel channel, Socket socket)
{
var ns = new NetworkStream(socket);
var stream = new SslStream(ns, true, OnRemoteCertifiateValidation);
try
{
X509CertificateCollection certificates = null;
if (Certificate != null)
{
certificates = new X509CertificateCollection(new[] { Certificate });
}
stream.AuthenticateAsClient(CommonName, certificates, Protocols, false);
}
catch (IOException err)
{
throw new InvalidOperationException("Failed to authenticate " + socket.RemoteEndPoint, err);
}
catch (ObjectDisposedException err)
{
throw new InvalidOperationException("Failed to create stream, did client disconnect directly?", err);
}
catch (AuthenticationException err)
{
throw new InvalidOperationException("Failed to authenticate " + socket.RemoteEndPoint, err);
}
return stream;
}
示例2: ClientConnectedEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="ClientConnectedEventArgs" /> class.
/// </summary>
/// <param name="channel">The channel.</param>
public ClientConnectedEventArgs(ITcpChannel channel)
{
if (channel == null) throw new ArgumentNullException("channel");
Channel = channel;
MayConnect = true;
SendResponse = true;
}
示例3: OnServeFiles
private static HttpResponse OnServeFiles(ITcpChannel channel, HttpRequest request)
{
//do not do anything, lib will handle it.
if (request.Uri.AbsolutePath.StartsWith("/cqs"))
return null;
var response = request.CreateResponse();
var uriWithoutTrailingSlash = request.Uri.AbsolutePath.TrimEnd('/');
var path = Debugger.IsAttached
? Path.GetFullPath(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\public\\", uriWithoutTrailingSlash))
: Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "public\\", uriWithoutTrailingSlash);
if (path.EndsWith("\\"))
path = Path.Combine(path, "index.html");
if (!File.Exists(path))
{
response.StatusCode = 404;
return response;
}
var stream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
var extension = Path.GetExtension(path).TrimStart('.');
response.ContentType = ApacheMimeTypes.Apache.MimeTypes[extension];
response.Body = stream;
return response;
}
示例4: 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;
}
}
示例5: 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();
}
示例6: StompClient
/// <summary>
/// </summary>
/// <param name="channel"></param>
/// <param name="transactionManager">
/// Must be unique for this client. i.e. the transaction ids used in this client is not
/// globally unique
/// </param>
public StompClient(ITcpChannel channel, ITransactionManager transactionManager)
{
if (channel == null) throw new ArgumentNullException("channel");
if (transactionManager == null) throw new ArgumentNullException("transactionManager");
Channel = channel;
_transactionManager = transactionManager;
}
示例7: ChannelErrorEventArgs
/// <summary>
/// Initializes a new instance of the <see cref="ClientDisconnectedEventArgs" /> class.
/// </summary>
/// <param name="channel">The channel that disconnected.</param>
/// <param name="exception">The exception that was caught.</param>
public ChannelErrorEventArgs(ITcpChannel channel, Exception exception)
{
if (channel == null) throw new ArgumentNullException("channel");
if (exception == null) throw new ArgumentNullException("exception");
Channel = channel;
Exception = exception;
}
示例8: FreeSwitch
public FreeSwitch(ref ITcpChannel channel) {
_channel = channel;
_channel.MessageSent += OnMessageSent;
_channel.ChannelFailure += OnError;
_requestsQueue = new ConcurrentQueue<CommandAsyncEvent>();
Error += OnError;
MessageReceived += OnMessageReceived;
}
示例9: OnMessage
protected override void OnMessage(ITcpChannel source, object msg)
{
var message = (IHttpMessage) msg;
// used to be able to send back all
message.Headers["X-Pipeline-index"] = (_pipelineIndex++).ToString();
base.OnMessage(source, msg);
}
示例10: ClientContext
public ClientContext(ITcpChannel channel, object message)
{
if (channel == null) throw new ArgumentNullException("channel");
_channel = channel;
RequestMessage = message;
ChannelData = Channel.Data;
RemoteEndPoint = channel.RemoteEndpoint;
RequestData = new DictionaryContextData();
}
示例11: OnMessage
private void OnMessage(ITcpChannel channel, object message)
{
if (channel.Data["lock"] == null)
{
Thread.Sleep(2000);
channel.Data["lock"] = new object();
}
else
_eventToTriggerBySecond.Set();
}
示例12: 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();
}
示例13: OnMessage
/// <summary>
/// Receive a new message from the specified client
/// </summary>
/// <param name="source">Channel for the client</param>
/// <param name="msg">Message (as decoded by the specified <see cref="IMessageDecoder" />).</param>
protected override void OnMessage(ITcpChannel source, object msg)
{
var message = (IHttpMessage) msg;
//TODO: Try again if we fail to update
var counter = (int) source.Data.GetOrAdd(HttpMessage.PipelineIndexKey, x => 0) + 1;
source.Data.TryUpdate(HttpMessage.PipelineIndexKey, counter, counter - 1);
message.Headers[HttpMessage.PipelineIndexKey] = counter.ToString();
var request = msg as IHttpRequest;
if (request != null)
request.RemoteEndPoint = source.RemoteEndpoint;
base.OnMessage(source, msg);
}
示例14: OnDisconnect
private void OnDisconnect(ITcpChannel arg1, Exception arg2)
{
_socket = null;
if (_sendCompletionSource != null)
{
_sendCompletionSource.SetException(arg2);
_sendCompletionSource = null;
}
if (_readCompletionSource != null)
{
_readCompletionSource.SetException(arg2);
_readCompletionSource = null;
}
}
示例15: RespondWithRaw
private bool RespondWithRaw(Stream body, int statusCode, string mimeType, Dictionary<string, string> headers = null)
{
ITcpChannel _channel;
lock (lockObject)
{
if (channel == null)
return false;
_channel = channel;
channel = null;
}
try
{
IHttpResponse response = request.CreateResponse();
request = null;
response.ContentLength = (int)body.Length;
response.StatusCode = statusCode;
response.ContentType = mimeType;
if (currentUser != null)
{
response.AddHeader("X-User-Name", currentUser.Value.name);
response.AddHeader("X-User-Readonly", currentUser.Value.readOnly ? "Yes" : "No");
}
response.AddHeader("Access-Control-Allow-Origin", "*");
response.AddHeader("Access-Control-Allow-Headers", "Authorization");
response.AddHeader("Access-Control-Allow-Methods", "POST, HEAD, PUT, DELETE, GET, OPTIONS");
if (headers != null)
foreach (KeyValuePair<string, string> kvp in headers)
response.AddHeader(kvp.Key, kvp.Value);
body.Position = 0;
response.Body = body;
_channel.Send(response);
}
catch
{
return false;
}
return true;
}