Пример #1
0
        protected void sendCallback(IAsyncResult ar)
        {
            var socket = (Socket)ar.AsyncState;

            try
            {
                helper.EndSend(ar, socket);
            }
            catch (SocketException)
            {
                OnDisconnected(instanceNodeId);
                return;
            }
            catch (ObjectDisposedException)
            {
                return;
            }

            buffer = new Byte[2048];

            try
            {
                helper.BeginReceive(buffer,
                                    new AsyncCallback(receiveCallback),
                                    socket);
            }
            catch (SocketException)
            {
                OnDisconnected(instanceNodeId);
                return;
            }
        }
Пример #2
0
        protected void sendCallback(IAsyncResult ar)
        {
            var   socket    = (Socket)ar.AsyncState;
            Int32 sentBytes = 0;

            try
            {
                sentBytes = helper.EndSend(ar, socket);
            }
            catch (SocketException)
            {
                // socket has become diconnected.
                OnDisconnected(instanceNodeId);
            }
            catch (ObjectDisposedException)
            {
                return;
            }

            // start receiving again
            buffer = new Byte[2048];
            try
            {
                helper.BeginReceive(buffer, new AsyncCallback(receiveCallback), socket);
            }
            catch (SocketException)
            {
                // socket has become diconnected.
                OnDisconnected(NodeId);
            }
            catch (ObjectDisposedException)
            {
                // socket/thread is being shut down. (no need to log this)
            }
        }