using System.Net;
using B24SiemensPlugin.TCP;
using Serilog;

namespace B24SiemensPlugin;

class SiemensServer : TcpServer
{
    public SiemensServer(int port=42010) : base(IPAddress.Any, port)
    {
    }
    public event Func<PLCPacket, PLCPacket> OnPLCPacket;
    protected override void OnConnected(TcpSession session)
    {
        Log.Logger.ForContext<SiemensServer>().Information("PLC client connected");
    }

    protected override TcpSession CreateSession()
    {
        var session = new SiemensTCPSession(this);
        session.OnPLCPacketReceived += OnPLCPacket;
        session.ReceiveAsync();
        return session;
    }
}