Exemplo n.º 1
0
        public void Disconnect()
        {
            _connecting = false;

            if (_client == null)
            {
                return;
            }
            var dataFrame = new DataFrame();

            dataFrame.Append(new byte[0]);

            var bytes = dataFrame.AsFrame()[0].Array;

            ReadyState = ReadyStates.CLOSING;

            bytes[0] = 0x88;
            if (_context != null && _context.UserContext != null)
            {
                _context.UserContext.Send(bytes);
            }

            _client.Close();
            _client    = null;
            ReadyState = ReadyStates.CLOSED;
        }
Exemplo n.º 2
0
 /// <summary>
 /// Sends the specified data.
 /// </summary>
 /// <param name="dataFrame">The data.</param>
 /// <param name="context">The user context.</param>
 /// <param name="raw">whether or not to send raw data</param>
 /// <param name="close">if set to <c>true</c> [close].</param>
 public void Send(DataFrame dataFrame, Context context, bool raw = false, bool close = false)
 {
     if (context.Connected)
     {
         AsyncCallback callback = EndSend;
         if (close)
         {
             callback = EndSendAndClose;
         }
         context.SendReady.Wait();
         try
         {
             List <ArraySegment <byte> > data = raw ? dataFrame.AsRaw() : dataFrame.AsFrame();
             context.Connection.Client.BeginSend(data, SocketFlags.None,
                                                 callback,
                                                 context);
         }
         catch
         {
             context.Disconnect();
         }
     }
 }