コード例 #1
0
        public DME_PooledSocket(DME_SocketPool socketPool, IPEndPoint endPoint, int sendReceiveTimeout)
        {
            this.socketPool = socketPool;
            Created = DateTime.Now;

            //Set up the socket.
            socket = new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.SendTimeout, sendReceiveTimeout);
            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, sendReceiveTimeout);
            socket.ReceiveTimeout = sendReceiveTimeout;
            socket.SendTimeout = sendReceiveTimeout;

            //Do not use Nagle's Algorithm
            socket.NoDelay = true;

            //Establish connection
            socket.Connect(endPoint);

            //Wraps two layers of streams around the socket for communication.
            stream = new BufferedStream(new NetworkStream(socket, false));
        }
コード例 #2
0
 private Dictionary<string, string> stats(DME_SocketPool pool)
 {
     if (pool == null) {
         return null;
     }
     Dictionary<string, string> result = new Dictionary<string, string>();
     serverPool.Execute(pool, delegate(DME_PooledSocket socket) {
         socket.Write("stats\r\n");
         string line;
         while (!(line = socket.ReadResponse().TrimEnd('\0', '\r', '\n')).StartsWith("END")) {
             string[] s = line.Split(' ');
             result.Add(s[1], s[2]);
         }
     });
     return result;
 }