Пример #1
0
        /// <summary>
        /// close conncetion, +/- blocking
        /// </summary>
        /// <param name="nextAction"></param>
        public void Disconnect(Action nextAction = null)
        {
            _writer.Reset();
            ComQuitPacket quitPacket = new ComQuitPacket(new PacketHeader());

            quitPacket.WritePacket(_writer);
            byte[] data = _writer.ToArray();
            //-------------------------------------
            InitWait();
            StartSend(data, 0, data.Length, () =>
            {
                socket.Shutdown(SocketShutdown.Both);
                _workingState = WorkingState.Disconnected;
                UnWait();
                if (nextAction != null)
                {
                    nextAction();
                }
            });
            if (nextAction == null)
            {
                Wait(); //block
            }
            else
            {
                UnWait();
            }
        }
Пример #2
0
        public void Disconnect()
        {
            _writer.Reset();
            ComQuitPacket quitPacket = new ComQuitPacket();

            quitPacket.WritePacket(_writer);

            int send = socket.Send(_writer.ToArray());

            socket.Disconnect(true);
        }
Пример #3
0
        public void DisconnectAsync(Action onClosed)
        {
            _writer.Reset();
            ComQuitPacket quitPacket = new ComQuitPacket();

            quitPacket.WritePacket(_writer);

            byte[] dataToSend = _writer.ToArray();
            _connSession.SetDataToSend(dataToSend, dataToSend.Length);

            _connSession.StartSend(recv =>
            {
                socket.Disconnect(true);

                return(EndSendState.Complete);
            });
        }
 /// <summary>
 /// close conncetion, +/- blocking
 /// </summary>
 /// <param name="nextAction"></param>
 public void Disconnect(Action nextAction = null)
 {
     _writer.Reset();
     ComQuitPacket quitPacket = new ComQuitPacket(new PacketHeader());
     quitPacket.WritePacket(_writer);
     byte[] data = _writer.ToArray();
     //-------------------------------------
     InitWait();
     StartSend(data, 0, data.Length, () =>
     {
         socket.Shutdown(SocketShutdown.Both);
         _workingState = WorkingState.Disconnected;
         UnWait();
         if (nextAction != null)
         {
             nextAction();
         }
     });
     if (nextAction == null)
     {
         Wait(); //block
     }
     else
     {
         UnWait();
     }
 }