本文整理汇总了C#中ITcpChannel类的典型用法代码示例。如果您正苦于以下问题:C# ITcpChannel类的具体用法?C# ITcpChannel怎么用?C# ITcpChannel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITcpChannel类属于命名空间,在下文中一共展示了ITcpChannel类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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;
}
开发者ID:krigans,项目名称:Griffin.Framework,代码行数:36,代码来源:ClientSideSslStreamBuilder.cs
示例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;
}
开发者ID:jakubmacek,项目名称:Griffin.Framework,代码行数:11,代码来源:ClientConnectedEventArgs.cs
示例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;
}
开发者ID:ricklxm,项目名称:Griffin.Framework,代码行数:27,代码来源:Program.cs
示例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;
}
}
开发者ID:ricklxm,项目名称:Griffin.Framework,代码行数:34,代码来源:LiteServer.cs
示例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();
}
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:8,代码来源:HttpListener.cs
示例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;
}
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:15,代码来源:StompClient.cs
示例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;
}
开发者ID:Tochemey,项目名称:NetFreeSwitch.Framework,代码行数:13,代码来源:ChannelErrorEventArgs.cs
示例8: FreeSwitch
public FreeSwitch(ref ITcpChannel channel) {
_channel = channel;
_channel.MessageSent += OnMessageSent;
_channel.ChannelFailure += OnError;
_requestsQueue = new ConcurrentQueue<CommandAsyncEvent>();
Error += OnError;
MessageReceived += OnMessageReceived;
}
开发者ID:Tochemey,项目名称:NetFreeSwitch.Framework,代码行数:8,代码来源:FreeSwitch.cs
示例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);
}
开发者ID:jorgenlidholm,项目名称:Griffin.Framework,代码行数:9,代码来源:HttpListener.cs
示例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();
}
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:9,代码来源:ClientContext.cs
示例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();
}
开发者ID:jakubmacek,项目名称:Griffin.Framework,代码行数:10,代码来源:Class1.cs
示例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();
}
开发者ID:VladimirTyrin,项目名称:Griffin.Framework,代码行数:10,代码来源:HttpListener.cs
示例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);
}
开发者ID:jgauffin,项目名称:Griffin.Framework,代码行数:21,代码来源:HttpListener.cs
示例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;
}
}
开发者ID:GitItInTheHub,项目名称:Griffin.Framework,代码行数:17,代码来源:StompClient.cs
示例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;
}
开发者ID:Doridian,项目名称:CorsairLinkPlusPlus,代码行数:45,代码来源:RequestHandler.cs
示例16: OnMessage
private static void OnMessage(ITcpChannel channel, object message)
{
var request = (HttpRequest)message;
var response = request.CreateResponse();
if (request.Uri.AbsolutePath.StartsWith("/restricted"))
{
var user = _authenticator.Authenticate(request);
if (user == null)
{
_authenticator.CreateChallenge(request, response);
channel.Send(response);
return;
}
Console.WriteLine("Logged in: " + user);
}
if (request.Uri.AbsolutePath == "/favicon.ico")
{
response.StatusCode = 404;
channel.Send(response);
return;
}
var msg = Encoding.UTF8.GetBytes("Hello world");
if (request.Uri.ToString().Contains(".jpg"))
{
response.Body = new FileStream(@"C:\users\gaujon01\Pictures\DSC_0231.jpg", FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
response.ContentType = "image/jpeg";
}
else
{
response.Body = new MemoryStream(msg);
//response.Body.Write(msg, 0, msg.Length);
response.ContentType = "text/plain";
}
channel.Send(response);
if (request.HttpVersion == "HTTP/1.0")
channel.Close();
}
开发者ID:ricklxm,项目名称:Griffin.Framework,代码行数:45,代码来源:Program.cs
示例17: 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 {
stream.AuthenticateAsServer(Certificate, UseClientCertificate, Protocols, CheckCertificateRevocation);
}
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;
}
开发者ID:Tochemey,项目名称:NetFreeSwitch.Framework,代码行数:25,代码来源:ServerSideSslStreamBuilder.cs
示例18: CreateChannel
private ITcpChannel CreateChannel()
{
if (_channel != null)
return _channel;
if (_sslStreamBuilder != null)
{
_channel = new SecureTcpChannel(new BufferSlice(new byte[65535], 0, 65535), _encoder, _decoder,
_sslStreamBuilder);
}
else
{
_channel = new TcpChannel(new BufferSlice(new byte[65535], 0, 65535), _encoder, _decoder);
}
_channel.Disconnected = OnDisconnect;
_channel.MessageSent = OnSendCompleted;
_channel.MessageReceived = OnChannelMessageReceived;
return _channel;
}
开发者ID:jakubmacek,项目名称:Griffin.Framework,代码行数:20,代码来源:MicroMessageClient.cs
示例19: OnSendCompleted
/// <summary>
/// Completed Send request event handler. Good for logging.
/// </summary>
/// <param name="channel">the Tcp channel used to send the request</param>
/// <param name="sentMessage">the message sent</param>
private void OnSendCompleted(ITcpChannel channel, object sentMessage) {
if (_log.IsDebugEnabled) {
var cmd = sentMessage as BaseCommand;
_log.Debug("command sent to freeSwitch <<{0}>>", cmd.ToString());
}
_sendCompletedSemaphore.Release();
}
开发者ID:Tochemey,项目名称:NetFreeSwitch.Framework,代码行数:13,代码来源:OutboundChannelSession.cs
示例20: OnMessageReceived
/// <summary>
/// Fired when a decoded message is received by the channel.
/// </summary>
/// <param name="channel">Receiving channel</param>
/// <param name="message">Decoded message received</param>
private async void OnMessageReceived(ITcpChannel channel, object message) {
var decodedMessage = message as EslDecodedMessage;
// Handle decoded message.
if (decodedMessage?.Headers == null
|| !decodedMessage.Headers.HasKeys())
return;
var headers = decodedMessage.Headers;
object response = null;
var contentType = headers["Content-Type"];
if (string.IsNullOrEmpty(contentType)) return;
contentType = contentType.ToLowerInvariant();
switch (contentType) {
case "auth/request":
if (OnAuthentication != null) await OnAuthentication(this, EventArgs.Empty).ConfigureAwait(false);
break;
case "command/reply":
var reply = new CommandReply(headers, decodedMessage.OriginalMessage);
response = reply;
break;
case "api/response":
var apiResponse = new ApiResponse(decodedMessage.BodyText);
response = apiResponse;
break;
case "text/event-plain":
var parameters = decodedMessage.BodyLines.AllKeys.ToDictionary(key => key,
key => decodedMessage.BodyLines[key]);
var @event = new EslEvent(parameters);
response = @event;
break;
case "log/data":
var logdata = new LogData(headers, decodedMessage.BodyText);
response = logdata;
break;
case "text/rude-rejection":
await _channel.CloseAsync();
var reject = new RudeRejection(decodedMessage.BodyText);
response = reject;
break;
case "text/disconnect-notice":
var notice = new DisconnectNotice(decodedMessage.BodyText);
response = notice;
break;
default:
// Here we are handling an unknown message
var msg = new EslMessage(decodedMessage.Headers, decodedMessage.OriginalMessage);
response = msg;
break;
}
await HandleResponse(response).ConfigureAwait(false);
}
开发者ID:Tochemey,项目名称:NetFreeSwitch.Framework,代码行数:56,代码来源:OutboundChannelSession.cs
注:本文中的ITcpChannel类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论