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()); } } }
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()); } }
//private Thread thread; protected abstract void DataReceived(TConnection sender, NetworkBuffer data);
public void OnDataReceived(NetworkConnection sender, NetworkBuffer data) { DataReceived((TConnection)sender, data); }