コード例 #1
0
        private static void RecvCallbackFromDevice(IAsyncResult ar)
        {
            RecvState state = (RecvState)ar.AsyncState;

            try
            {
                // Retrieve the state object and the client socket
                // from the asynchronous state object.

                // can get the disconnected socket status
                if (state.m_Socket.Connected == false)
                {
                    return;
                }
                // Read data from the remote device.
                int bytesRead = state.m_Socket.EndReceive(ar);
                ParseBuffer(state, bytesRead);
            }
            catch (ObjectDisposedException)
            {
                // DisposedException is received if the current host initiated
                // a disconnection. In this case - do nothing.
            }
            catch (Exception e)
            {
                state.m_OnExcp(e);
            }
        }