Advertisement
Guest User

Untitled

a guest
Nov 15th, 2024
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.89 KB | None | 0 0
  1. using System;
  2. using System.Net;
  3. using System.Net.Sockets;
  4. using System.Windows.Forms;
  5. using System.Collections.Generic;
  6.  
  7. namespace Server.Classes
  8. {
  9.     internal class Connection
  10.     {
  11.         private Socket listener;
  12.         private List<Socket> clients;
  13.  
  14.         public Connection()
  15.         {
  16.             listener = new Socket(IPAddress.Any.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
  17.         }
  18.  
  19.         public event EventHandler onReceived;
  20.         public event EventHandler onConnected;
  21.  
  22.         public void Listen()
  23.         {
  24.             try
  25.             {
  26.                 listener.Bind(new IPEndPoint(IPAddress.Any, Settings.Connection.Port));
  27.                 listener.Listen(10);
  28.             }
  29.             catch (Exception ex)
  30.             {
  31.                 {
  32.                     MessageBox.Show(ex.ToString());
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
  38.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement