本文整理汇总了C#中ISocket类的典型用法代码示例。如果您正苦于以下问题:C# ISocket类的具体用法?C# ISocket怎么用?C# ISocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISocket类属于命名空间,在下文中一共展示了ISocket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHeaders
public static Task<IEnumerable<KeyValuePair<string, string>>> GetHeaders(ISocket socket)
{
var headers = new MemoryStream ();
return Util.ReadExactly (socket, 10).ContinueWith (t =>
{
t.PropagateExceptions ();
byte[] lenBuffer = t.Result;
int pos = Array.IndexOf (lenBuffer, (byte)':');
var lenString = Encoding.UTF8.GetString (lenBuffer, 0, pos);
var len = int.Parse (lenString) + 1;
pos++;
var alreadyReadLen = lenBuffer.Length - pos;
headers.Write (lenBuffer, pos, alreadyReadLen);
return Util.ReadDataAsync (socket, headers, len - alreadyReadLen);
}).Unwrap ().ContinueWith (t2 =>
{
t2.PropagateExceptions ();
var rv = new List<KeyValuePair<string, string>> ();
var headerPairs = Encoding.UTF8.GetString (headers.ToArray ()).Split ((char)0);
for (var i = 0; i < headerPairs.Length - 1; i += 2)
rv.Add (new KeyValuePair<string, string> (headerPairs[i], headerPairs[i + 1]));
return Util.TaskFromResult ((IEnumerable<KeyValuePair<string, string>>)rv);
}).Unwrap ();
}
示例2: CloseSock
public static void CloseSock(ISocket socket, int timeout = 0)
{
if (socket.GetSocket().ProtocolType == ProtocolType.Tcp) socket.GetSocket().Shutdown(SocketShutdown.Both);
if (timeout == 0) socket.Close();
else socket.Close(timeout);
}
示例3: SocketSender
public SocketSender(IFireflyService service, ISocket socket)
{
_service = service;
_socket = socket;
_state = State.Immediate;
_socketEvent = _service.Memory.AllocSocketEvent();
}
示例4: NodeBase
protected NodeBase(ICluster owner, IPEndPoint endpoint, IFailurePolicy failurePolicy, ISocket socket)
{
this.owner = owner;
this.endpoint = endpoint;
this.socket = socket;
this.failurePolicy = failurePolicy;
this.name = endpoint.ToString();
failLock = new Object();
writeQueue = new ConcurrentQueue<Data>();
readQueue = new Queue<Data>();
mustReconnect = true;
IsAlive = true;
counterEnqueuePerSec = Metrics.Meter("node write enqueue/sec", endpoint.ToString(), Interval.Seconds);
counterDequeuePerSec = Metrics.Meter("node write dequeue/sec", endpoint.ToString(), Interval.Seconds);
counterOpReadPerSec = Metrics.Meter("node op read/sec", endpoint.ToString(), Interval.Seconds);
counterWriteQueue = Metrics.Counter("write queue length", endpoint.ToString());
counterReadQueue = Metrics.Counter("read queue length", endpoint.ToString());
counterWritePerSec = Metrics.Meter("node write/sec", endpoint.ToString(), Interval.Seconds);
counterErrorPerSec = Metrics.Meter("node in error/sec", endpoint.ToString(), Interval.Seconds);
counterItemCount = Metrics.Counter("commands", endpoint.ToString());
gaugeSendSpeed = Metrics.Gauge("send speed", endpoint.ToString());
}
示例5: StreamProxy
public StreamProxy(ISocket inStream, ISocket outStream, int bufferSize = 16384)
{
Logger.Debug("Setting up Stream Proxy from " + inStream.GetType() + " to " + outStream.GetType() + "(bufsize=" + bufferSize + ")");
_inStream = inStream;
_outStream = outStream;
_bufferSize = bufferSize;
}
示例6: EngageWith
public void EngageWith(ISocket socket)
{
Interlocked.Exchange(ref _flushingInProgress, 0);
Interlocked.Exchange(ref _writingOffset, 0);
Interlocked.Exchange(ref _socketException, null);
_asyncSocket.EngageWith(socket);
}
示例7: Receiver
public Receiver(ISocket socket, Action<string> messageAction, Action closeAction)
{
_socket = socket;
_messageAction = messageAction;
_closeAction = closeAction;
_queue = new Queue<byte>();
}
示例8: Connection
public Connection(IServerTrace trace, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
{
_trace = trace;
_app = app;
_socket = socket;
_disconnected = disconnected;
}
示例9: ClacksClient
public ClacksClient(ISocket socket) {
if(socket == null) {
throw new ArgumentNullException("socket");
}
_socket = socket;
_receiver = new ResponseReceiver(_socket);
}
示例10: OnClientConnect
private void OnClientConnect(ISocket clientSocket)
{
FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString()));
ListenForClients();
WebSocketConnection connection = null;
connection = new WebSocketConnection(
clientSocket,
_config,
bytes => RequestParser.Parse(bytes, _scheme),
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b),
b => connection.OnPing(b),
b => connection.OnPong(b)),
s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s));
if (IsSecure)
{
FleckLog.Debug("Authenticating Secure Connection");
clientSocket
.Authenticate(Certificate,
connection.StartReceiving,
e => FleckLog.Warn("Failed to Authenticate", e));
}
else
{
connection.StartReceiving();
}
}
示例11: KayakContext
/// <summary>
/// Constructs a new KayakContext with the provided `ISocket`, `IKayakServerRequest`, and
/// `IKayakServerResponse` objects.
/// </summary>
public KayakContext(ISocket socket, IKayakServerRequest request, IKayakServerResponse response)
{
Socket = socket;
Request = request;
Response = response;
Items = new Dictionary<object, object>();
}
示例12: CreateContext
public static KayakContext CreateContext(ISocket socket)
{
var request = new KayakServerRequest(socket);
var response = new KayakServerResponse(socket);
return new KayakContext(socket, request, response);
}
示例13: BeginRequestInternal
public IEnumerable<object> BeginRequestInternal(ISocket socket)
{
var bufferHeaders = new ContinuationState<LinkedList<ArraySegment<byte>>>(socket.BufferHeaders());
yield return bufferHeaders;
var headerBuffers = bufferHeaders.Result;
Dictionary<string, object> env = new Dictionary<string, object>();
var bodyDataReadWithHeaders = headerBuffers.Last.Value;
headerBuffers.RemoveLast();
var headersString = headerBuffers.GetString();
var reader = new StringReader(headersString);
var requestLine = reader.ReadRequestLine();
var headers = reader.ReadHeaders();
env["Owin.RequestMethod"] = requestLine.Verb;
env["Owin.RequestUri"] = requestLine.RequestUri;
env["Owin.RequestHeaders"] = headers;
env["Owin.BaseUri"] = "";
env["Owin.RemoteEndPoint"] = socket.RemoteEndPoint;
env["Owin.RequestBody"] = CreateReadBody(socket, bodyDataReadWithHeaders);
// TODO provide better values
env["Owin.ServerName"] = "";
env["Owin.ServerPort"] = 0;
env["Owin.UriScheme"] = "http";
yield return env;
}
示例14: EngageWith
public void EngageWith(ISocket socket)
{
_socket = socket;
_notIoArgs.AcceptSocket = _socket.UnderlyingSocket;
_receiveArgs.AcceptSocket = _socket.UnderlyingSocket;
_sendArgs.AcceptSocket = _socket.UnderlyingSocket;
}
示例15: OnClientConnect
private void OnClientConnect(ISocket clientSocket)
{
FleckLog.Debug("Client Connected");
ListenForClients();
WebSocketConnection connection = null;
connection = new WebSocketConnection(
clientSocket,
_config,
bytes => RequestParser.Parse(bytes, _scheme),
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b)));
if (IsSecure)
{
FleckLog.Debug("Authenticating Secure Connection");
clientSocket
.Authenticate(_x509Certificate,
connection.StartReceiving,
e => FleckLog.Warn("Failed to Authenticate", e));
}
else
{
connection.StartReceiving();
}
}