Ejemplo n.º 1
0
        private void Remote_OnConnected(object sender, AsyncClientEventArgs e)
        {
            if (_OnDisposing)
            {
                return;
            }
            Debug.Print("Remote connected");

            _Client.Socket.SendTimeout    = _WriteTimeout;
            _Client.Socket.ReceiveTimeout = _ReadTimeout;

            #region 產生事件
            if (!_OnDisposing && this.OnConnected != null)
            {
                foreach (EventHandler <AsyncClientEventArgs> del in this.OnConnected.GetInvocationList())
                {
                    if (_OnDisposing)
                    {
                        return;
                    }
                    try { del.BeginInvoke(this, e, new AsyncCallback(EventCallback), del); }
                    catch (Exception ex) { Debug.Print(ex.Message); }
                }
            }
            #endregion
        }
Ejemplo n.º 2
0
 void Client_OnConnected(object sender, AsyncClientEventArgs e)
 {
     WriteLog("已連接至伺服器");
     SetTextBoxFocus(txtSendMsg);
     SetControlEnabled(btnStart, false);
     SetControlEnabled(btnStop, true);
 }
Ejemplo n.º 3
0
        private void ac_OnClosed(object sender, AsyncClientEventArgs e)
        {
            WebSocketClient ac = sender as WebSocketClient;

            if (ac != null)
            {
                m_Clients.TryRemove(ac.RemoteEndPoint.ToString(), out AsyncClient acc);
            }
            base.OnClientClosed(ac, e.ClosedByIdle, e.ExtraInfo);
        }
Ejemplo n.º 4
0
 private void Remote_OnSendedFail(object sender, AsyncClientEventArgs e)
 {
     if (_OnDisposing)
     {
         return;
     }
     byte[] tmp = new byte[e.Data.Length];
     Array.Copy(e.Data, tmp, tmp.Length);
     Debug.Print($"Send fail {tmp.Length} bytes.");
     Debug.Print($"Data:{tmp.ToHexString()}");
 }
Ejemplo n.º 5
0
 private void ac_OnBeforeSended(object sender, AsyncClientEventArgs e)
 {
     try
     {
         if (!m_IsShutdown && !m_IsDisposed)
         {
             m_Counters[ServerCounterType.BytesOfSendQueue]?.IncrementBy(e.Data.Length);
         }
     }
     catch (Exception ex) { Debug.Print(ex.Message); }
 }
Ejemplo n.º 6
0
 private void ac_OnSendedFail(object sender, AsyncClientEventArgs e)
 {
     try
     {
         if (!m_IsShutdown && !m_IsDisposed)
         {
             m_Counters[ServerCounterType.SendFail]?.Increment();
             m_Counters[ServerCounterType.RateOfSendFail]?.Increment();
             m_Counters[ServerCounterType.BytesOfSendQueue]?.IncrementBy(-e.Data.Length);
         }
     }
     catch (Exception ex) { Debug.Print(ex.Message); }
     base.OnSendedFail(sender as WebSocketClient, e.Data, e.ExtraInfo);
 }
Ejemplo n.º 7
0
        private void ac_OnDataSended(object sender, AsyncClientEventArgs e)
        {
            try
            {
                int count = e.Data.Length;
                if (!m_IsShutdown && !m_IsDisposed)
                {
                    m_Counters[ServerCounterType.TotalSendedBytes]?.IncrementBy(count);
                    m_Counters[ServerCounterType.RateOfSendedBytes]?.IncrementBy(count);
                    m_Counters[ServerCounterType.BytesOfSendQueue]?.IncrementBy(-count);
                }
            }
            catch (Exception ex) { Debug.Print(ex.Message); }

            base.OnDataSended((WebSocketClient)sender, e.Data, e.ExtraInfo);
        }
Ejemplo n.º 8
0
        private void Remote_OnClosed(object sender, AsyncClientEventArgs e)
        {
            if (_OnDisposing)
            {
                return;
            }
            Debug.Print("Remote disconnected");

            #region 產生事件
            if (!_OnDisposing && this.OnDisconnect != null)
            {
                foreach (EventHandler <AsyncClientEventArgs> del in this.OnDisconnect.GetInvocationList())
                {
                    if (_OnDisposing)
                    {
                        return;
                    }
                    try { del.BeginInvoke(this, e, new AsyncCallback(EventCallback), del); }
                    catch (Exception ex) { Debug.Print(ex.Message); }
                }
            }
            #endregion
        }
Ejemplo n.º 9
0
 void Client_OnDataReceived(object sender, AsyncClientEventArgs e)
 {
     WriteLog("從伺服器收到 {0} Bytes", e.Data.Length);
     WriteLog(" > :{0}", Encoding.Default.GetString(e.Data));
     WriteLog("Hex:{0}", e.Data.ToHexString());
 }
Ejemplo n.º 10
0
 void Client_OnDataSended(object sender, AsyncClientEventArgs e)
 {
     WriteLog("已發送 {0} Bytes 至伺服器", e.Data.Length);
     WriteLog(" < :{0}", Encoding.Default.GetString(e.Data));
     WriteLog("Hex:{0}", e.Data.ToHexString());
 }
Ejemplo n.º 11
0
 void Client_OnClosing(object sender, AsyncClientEventArgs e)
 {
     WriteLog("正與伺服器中斷連線中");
 }
Ejemplo n.º 12
0
 void Client_OnClosed(object sender, AsyncClientEventArgs e)
 {
     WriteLog("已與伺服器中斷連線");
     SetControlEnabled(btnStart, true);
     SetControlEnabled(btnStop, false);
 }
Ejemplo n.º 13
0
 void Client_OnException(object sender, AsyncClientEventArgs e)
 {
     WriteLog("發生錯誤");
     WriteLog(e.Exception.Message);
 }