mirror-ac/server/Server.cs

47 lines
1.2 KiB
C#
Raw Normal View History

2023-09-02 17:56:46 +02:00
using System.IO;
using System;
using System.Net;
2023-09-02 15:47:15 +02:00
using System.Net.Sockets;
using System.Reflection.Metadata.Ecma335;
using System.Text;
using server;
2023-09-02 17:56:46 +02:00
using Serilog;
2023-09-02 15:47:15 +02:00
namespace server
{
public class Server
{
private IPEndPoint _ipEndPoint;
private TcpListener _tcpListener;
2023-09-02 17:56:46 +02:00
private ILogger _logger;
private byte[] _buffer;
private int _bufferSize;
2023-09-02 15:47:15 +02:00
2023-09-02 17:56:46 +02:00
private const int MAX_BUFFER_SIZE = 8192;
public Server(ILogger logger)
2023-09-02 15:47:15 +02:00
{
_ipEndPoint = new IPEndPoint(IPAddress.Any, 8888);
_tcpListener = new TcpListener(_ipEndPoint);
2023-09-02 17:56:46 +02:00
_buffer = new byte[MAX_BUFFER_SIZE];
_logger = logger;
2023-09-02 15:47:15 +02:00
}
public async Task Listen()
{
_tcpListener.Start();
2023-09-02 17:56:46 +02:00
_logger.Information("Listening for incoming connections...");
while (true)
{
using TcpClient _client = await _tcpListener.AcceptTcpClientAsync();
NetworkStream _stream = _client.GetStream();
_stream.Read(_buffer, 0, MAX_BUFFER_SIZE);
2023-09-02 15:47:15 +02:00
2023-09-02 17:56:46 +02:00
Message message = new Message(_buffer, _bufferSize, _logger);
}
2023-09-02 15:47:15 +02:00
}
}
}