예제 #1
0
 protected virtual void DataReceived(NetworkBuffer data)
 {
     if (OnDataReceived != null)
     {
         try
         {
             OnDataReceived?.Invoke(this, data);
         }
         catch (Exception ex)
         {
             Global.Log("NetworkConenction:DataReceived", LogType.Error, ex.ToString());
         }
     }
 }
예제 #2
0
        private void Socket_OnReceive(NetworkBuffer buffer)
        {
            try
            {
                // Unassigned ?
                if (sock == null)
                {
                    return;
                }

                // Closed ?
                if (sock.State == SocketState.Closed || sock.State == SocketState.Terminated) // || !connected)
                {
                    return;
                }

                lastAction = DateTime.Now;

                if (!processing)
                {
                    processing = true;

                    try
                    {
                        //lock(buffer.SyncLock)
                        while (buffer.Available > 0 && !buffer.Protected)
                        {
                            DataReceived(buffer);
                        }
                    }
                    catch
                    {
                    }

                    processing = false;
                }
            }
            catch (Exception ex)
            {
                Global.Log("NetworkConnection", LogType.Warning, ex.ToString());
            }
        }
예제 #3
0
        //private Thread thread;

        protected abstract void DataReceived(TConnection sender, NetworkBuffer data);
예제 #4
0
 public void OnDataReceived(NetworkConnection sender, NetworkBuffer data)
 {
     DataReceived((TConnection)sender, data);
 }