public void SendSocketData(Socket psocket, byte[] data, object userState)
 {
     try
     {
         if (psocket != null && IsSocketConnected(psocket))
         {
             lock (psocket)
             {
                 SocketSendState state = new SocketSendState(psocket, userState);
                 psocket.BeginSend(data, 0, data.Length, SocketFlags.None, EndSendCallback, state);
             }
         }
         else
         {
             OnDisconnected();
         }
     }
     catch (SocketException sex)
     {
         if (sex.NativeErrorCode != 10035)  //10035: WSAEWOULDBLOCK
         {
             Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Error while sending network message. Error message: " + sex.Message);
             OnDisconnected();
         }
     }
     catch (ObjectDisposedException)
     {
         // the connection is closed
         OnDisconnected();
     }
     catch (Exception e)
     {
         throw new MSNPSharpException("Error while sending network message. See the inner exception for more details.", e);
     }
 }
        protected virtual void EndSendCallback(IAsyncResult ar)
        {
            SocketSendState state = (SocketSendState)ar.AsyncState;

            try
            {
                state.Socket.EndSend(ar);

                OnAfterRawDataSent(state.UserState);
            }
            catch (SocketException sex)
            {
                if (sex.NativeErrorCode != 10035)  //10035: WSAEWOULDBLOCK
                {
                    Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Error while sending network message. Error message: " + sex.Message);
                    OnDisconnected();
                }
            }
            catch (ObjectDisposedException)
            {
                // the connection is closed
                OnDisconnected();
            }
            catch (Exception e)
            {
                throw new MSNPSharpException("Error while sending network message. See the inner exception for more details.", e);
            }
        }
 public void SendSocketData(Socket psocket, byte[] data, object userState)
 {
     try
     {
         if (psocket != null && IsSocketConnected(psocket))
         {
             lock (psocket)
             {
                 SocketSendState state = new SocketSendState(psocket, userState);
                 psocket.BeginSend(data, 0, data.Length, SocketFlags.None, EndSendCallback, state);
             }
         }
         else
         {
             OnDisconnected();
         }
     }
     catch (SocketException sex)
     {
         if (sex.NativeErrorCode != 10035)  //10035: WSAEWOULDBLOCK
         {
             Trace.WriteLineIf(Settings.TraceSwitch.TraceError, "Error while sending network message. Error message: " + sex.Message);
             OnDisconnected();
         }
     }
     catch (ObjectDisposedException)
     {
         // the connection is closed
         OnDisconnected();
     }
     catch (Exception e)
     {
         throw new MSNPSharpException("Error while sending network message. See the inner exception for more details.", e);
     }
 }