当前位置: 首页>>代码示例>>C#>>正文


C# ISocket类代码示例

本文整理汇总了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 ();
        }
开发者ID:kekekeks,项目名称:scgi-sharp,代码行数:31,代码来源:ScgiParser.cs

示例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);
        }
开发者ID:jccprj,项目名称:AwesomeSockets,代码行数:7,代码来源:AweSock.cs

示例3: SocketSender

 public SocketSender(IFireflyService service, ISocket socket)
 {
     _service = service;
     _socket = socket;
     _state = State.Immediate;
     _socketEvent = _service.Memory.AllocSocketEvent();
 }
开发者ID:virajs,项目名称:firefly,代码行数:7,代码来源:SocketSender.cs

示例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());
		}
开发者ID:adamhathcock,项目名称:EnyimMemcached2,代码行数:26,代码来源:NodeBase.cs

示例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;
 }
开发者ID:gwupe,项目名称:Gwupe,代码行数:7,代码来源:StreamProxy.cs

示例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);
 }
开发者ID:tomeucapo,项目名称:RedisBoost,代码行数:7,代码来源:RedisSender.cs

示例7: Receiver

 public Receiver(ISocket socket, Action<string> messageAction, Action closeAction)
 {
     _socket = socket;
     _messageAction = messageAction;
     _closeAction = closeAction;
     _queue = new Queue<byte>();
 }
开发者ID:emiaj,项目名称:Fleck,代码行数:7,代码来源:Receiver.cs

示例8: Connection

 public Connection(IServerTrace trace, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
 {
     _trace = trace;
     _app = app;
     _socket = socket;
     _disconnected = disconnected;
 }
开发者ID:friesencr,项目名称:dragonfly,代码行数:7,代码来源:Connection.cs

示例9: ClacksClient

 public ClacksClient(ISocket socket) {
     if(socket == null) {
         throw new ArgumentNullException("socket");
     }
     _socket = socket;
     _receiver = new ResponseReceiver(_socket);
 }
开发者ID:MindTouch,项目名称:MindTouch.Clacks,代码行数:7,代码来源:ClacksClient.cs

示例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();
            }
        }
开发者ID:vishnumitraha,项目名称:seb-win,代码行数:32,代码来源:WebSocketServer.cs

示例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>();
 }
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:11,代码来源:KayakContext.cs

示例12: CreateContext

        public static KayakContext CreateContext(ISocket socket)
        {
            var request = new KayakServerRequest(socket);
            var response = new KayakServerResponse(socket);

            return new KayakContext(socket, request, response);
        }
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:7,代码来源:KayakContext.cs

示例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;
        }
开发者ID:lovewitty,项目名称:OstrichNet,代码行数:31,代码来源:HttpSupport.cs

示例14: EngageWith

 public void EngageWith(ISocket socket)
 {
     _socket = socket;
     _notIoArgs.AcceptSocket = _socket.UnderlyingSocket;
     _receiveArgs.AcceptSocket = _socket.UnderlyingSocket;
     _sendArgs.AcceptSocket = _socket.UnderlyingSocket;
 }
开发者ID:okusnadi,项目名称:RedisBoost,代码行数:7,代码来源:AsyncSocketWrapper.cs

示例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();
            }
        }
开发者ID:Chossing,项目名称:EECS-582,代码行数:29,代码来源:WebSocketServer.cs


注:本文中的ISocket类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。