/// <summary>On socket disconnected.</summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> void OnAcceptedSocketDisconnected(object sender, SocketEventArgs e) { lock (AcceptedSockets) { if (e.ConnectionState == ConnectionState.Disconnected) { if (AcceptedSockets.Contains(e.Socket)) { Debug.Print("DISCONNECTED! " + AcceptedSockets.Count); AcceptedSockets.Remove(e.Socket); } } } }
/// <summary>On client socket connected.</summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> void OnConnectionStateChanged(object sender, SocketEventArgs e) { if (e.ConnectionState == ConnectionState.Disconnected) if (ClientSockets.Contains(e.Socket)) ClientSockets.Remove(e.Socket); }
/// <summary>On data received.</summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> void OnDataReceived(object sender, SocketEventArgs e) { DataReceived.Add(e.Buffer); Debug.Print(e.Buffer.Length.ToString(CultureInfo.InvariantCulture)); }
/// <summary>On connection accepted</summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> void OnClientSocketAccepted(object sender, SocketEventArgs e) { lock (AcceptedSockets) { AcceptedSockets.Add(e.Socket); e.Socket.DataReceived += OnDataReceived; e.Socket.ConnectionStateChanged += OnAcceptedSocketDisconnected; Debug.Print("ACCEPTED! " + AcceptedSockets.Count); } }