public void Start(Action<TcpClient, byte[]> onData, Action<TcpClient> onDisconnect)
{
TcpListener listener = new TcpListener(port);
listener.Start();
running = true;
AutoResetEvent are = new AutoResetEvent(false);
agent = new Agent<Action>(
() => { },
() => { },
nextaction =>
{
nextaction();
if (running)
{
return NextAction.WaitForNextMessage;
}
are.Set();
return NextAction.Finish;
});
agent.Start();
agent.SendMessage(() => { StartAccepting(listener, onData, onDisconnect); });
are.WaitOne();
listener.Stop();
}