Esempio n. 1
0
        /// <summary>
        /// Creates a ClientConnection from the socket, then begins communicating with it.
        /// </summary>
        public ClientConnection(Socket s, SimpleChatServer server)
        {
            this.server = server;
            // Record the socket and clear incoming
            socket   = s;
            incoming = new StringBuilder();
            outgoing = new StringBuilder();

            // Ask the socket to call MessageReceive as soon as up to 1024 bytes arrive.
            socket.BeginReceive(incomingBytes, 0, incomingBytes.Length,
                                SocketFlags.None, MessageReceived, null);
        }
Esempio n. 2
0
        /// <summary>
        /// Creates a ClientConnection from the socket, then begins communicating with it.
        /// </summary>
        public ClientConnection(Socket s, SimpleChatServer server)
        {
            // Record the socket and server and initialize incoming/outgoing
            this.server = server;
            socket      = s;
            incoming    = new StringBuilder();
            outgoing    = new StringBuilder();

            try
            {
                // Ask the socket to call MessageReceive as soon as up to 1024 bytes arrive.
                socket.BeginReceive(incomingBytes, 0, incomingBytes.Length,
                                    SocketFlags.None, MessageReceived, null);
            }
            catch (ObjectDisposedException)
            {
            }
        }