This repository has been archived on 2025-05-14. You can view files and clone it, but cannot push or open issues or pull requests.
Files
CardMarketBotServer/CardMarketServer/Program.cs
2023-08-01 14:04:38 +02:00

48 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();
client.startClient(clientSocket);
Console.WriteLine($"{GetClientCount()} clients connected");
}
}
}
}