Beispiel #1
0
        /// <summary>
        /// Called by OS when socket connects to server.
        /// After this, user should send any initial data, then call i_want_more_data
        /// </summary>
        private static void Connected_to_Server(IAsyncResult stateInResult)
        {
            PreservedState state = (PreservedState)stateInResult.AsyncState;

            state.callback();
            if (!state.socket.Connected)
            {
                return;
            }
            state.socket.EndConnect(stateInResult);
        }
Beispiel #2
0
        /// <summary>
        /// Called by OS when new data arrives.
        /// </summary>
        public static void ReceiveCallback(IAsyncResult stateInResult)
        {
            PreservedState state = (PreservedState)stateInResult.AsyncState;
            int            read  = state.socket.EndReceive(stateInResult);

            if (read == 0)
            {
                state.socket.Close();
            }
            else
            {
                state._HandleData(encoding, read);
                state.callback();
            }
        }