예제 #1
0
 /// <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);
             }
         }
     }
 }
예제 #2
0
 /// <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);
 }
예제 #3
0
 /// <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));
 }
예제 #4
0
 /// <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);
     }
 }