49 lines
1.4 KiB
C#
49 lines
1.4 KiB
C#
using System.Net;
|
|
using System.Net.Sockets;
|
|
|
|
namespace CardMarketServer
|
|
{
|
|
internal class Program
|
|
{
|
|
private static object _lock = new object();
|
|
private static readonly List<TcpClient> _clients = new List<TcpClient>();
|
|
|
|
public static TcpClient[] GetClients()
|
|
{
|
|
lock(_lock ) return _clients.ToArray();
|
|
}
|
|
|
|
public static int GetClientCount()
|
|
{
|
|
lock(_lock) return _clients.Count;
|
|
}
|
|
|
|
public static void RemoveClient(TcpClient client)
|
|
{
|
|
lock(_lock) _clients.Remove(client);
|
|
}
|
|
|
|
public static void AddClient(TcpClient client)
|
|
{
|
|
lock(_lock) _clients.Add(client);
|
|
}
|
|
static void Main(string[] args)
|
|
{
|
|
IPAddress ip = IPAddress.Parse("0.0.0.0");
|
|
TcpListener ServerSocket = new TcpListener(ip, 4000);
|
|
ServerSocket.Start();
|
|
Console.WriteLine("Server started");
|
|
while(true)
|
|
{
|
|
TcpClient clientSocket = ServerSocket.AcceptTcpClient();
|
|
//Console.WriteLine($"Client connected: {clientSocket.Client.RemoteEndPoint}");
|
|
AddClient(clientSocket);
|
|
handleClient client = new handleClient(new UsedRepository(),clientSocket);
|
|
client.startClient();
|
|
|
|
//Console.WriteLine($"{GetClientCount()} clients connected");
|
|
}
|
|
}
|
|
}
|
|
}
|