Initial commit
This commit is contained in:
48
CardMarketServer/Program.cs
Normal file
48
CardMarketServer/Program.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user