示例#1
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();
         }
     }
 }