public static void Test() { var listener = new TcpEndPointListener(null, 8080); var messager1 = new TcpMessager<SessionData3>(listener); messager1.DataReceived += messager1_DataReceived; listener.Start(); var task = new ThreadStart(() => { var messager2 = new TcpMessager<SessionData3>(); messager2.DataReceived += (sender, session, data) => { var str = Encoding.Default.GetString(data.Array, data.Offset, data.Count); Console.WriteLine("[messager2_DataReceived], " + str); int result = int.Parse(str); if (result != session.Data.a + session.Data.b) { Console.WriteLine("Wrong!"); } sendAddOrClose(session); }; messager2.SessionEnded += (sender, session) => { createClient(sender); }; createClient(messager2); }); new Thread(task).Start(); }
public static void TcpMessagerTester() { var listener = new TcpEndPointListener(null, 8080); var messager = new TcpMessager<SessionData>(100, data => { data.Messager = null; data.Buffer = null; data.Connection = null; }, listener); listener.Start(); messager.IncomingSessionStarted += messager_IncomingConnectionEstablished; messager.DataReceived += messager_DataReceived; }