protected virtual void OnClosed(SocketEventArgs e) { if (Closed != null) { Closed(this, e); } }
protected virtual void OnOpen(SocketEventArgs e) { if (Open != null) { Open(this, e); } }
protected virtual void OnDisconnected(SocketEventArgs e) { if (Disconnected != null) { Disconnected(this, e); } }
void OnSocketDataReceived(object sender, SocketEventArgs e) { lock (_receiveLock) { try { // Stores data into temporary stream var oldPos = _receiveStream.Position; _receiveStream.Write(e.Buffer, 0, e.Buffer.Length); _receiveStream.Position = oldPos; } catch (Exception ex) { Debug.WriteLine(ex.Message); Disconnect(); } while (true) { object packet = null; try { packet = _protocol.Read(_receiveStream); if (packet == null) break; var evnt = PacketReceived; if (evnt != null) evnt(this, new PeerEventArgs(this, packet)); } catch (Exception ex) { Debug.WriteLine(packet + ": " + ex.Message); Disconnect(); } } } }
void OnSocketConnectionStateChanged(object sender, SocketEventArgs e) { if (ConnectionStateChanged == null) return; var evnt = ConnectionStateChanged; evnt(this, new PeerEventArgs(this, e.ConnectionState)); }
protected virtual void OnClosed(SocketEventArgs e) { if (Closed != null) Closed(this, e); }
protected virtual void OnOpen(SocketEventArgs e) { if (Open != null) Open(this, e); }
protected virtual void OnDisconnected(SocketEventArgs e) { if (Disconnected != null) Disconnected(this, e); }
private void OnClientDisconnect(object sender, SocketEventArgs e) {// notif when client disconnected }
private void OnClientConnected(object sender, SocketEventArgs e) { // notif when client connected }
/// <summary>On connection accepted.</summary> /// <param name="sender"></param> /// <param name="e"></param> void OnSocketClientSocketAccepted(object sender, SocketEventArgs e) { var evnt = PeerConnected; if (evnt != null) evnt(this, new PeerEventArgs(new Peer(e.Socket, _protocol), ConnectionState.Connected)); }