public void DoubleDisposeTest() { var connector = new KcpConnector(123, "127.0.0.1", 7777); connector.Dispose(); connector.Dispose(); }
public void SimpleKcpTest() { lock (syncRoot) { connector = new KcpConnector(7758, "127.0.0.1", 7777); exitFlag = false; var thread = new Thread(Tick); thread.Start(); var data = new byte[0]; var server = new KcpTestsServer(7758, (d) => { data = d; }); var reData = new byte[0]; connector.On(SocketEvents.Message, (d) => { reData = d as byte[]; }); var wait = connector.Connect(); if (!Util.Wait(wait, 3000)) { exitFlag = true; server.Dispose(); connector.Dispose(); Assert.Fail("wait faild"); } wait = connector.Send(System.Text.Encoding.Default.GetBytes("hello world")); if (!Util.Wait(wait, 3000) || !Util.Wait(ref data, 3000) || !Util.Wait(ref reData, 3000)) { exitFlag = true; server.Dispose(); connector.Dispose(); Assert.Fail("wait faild"); } exitFlag = true; server.Dispose(); connector.Disconnect(); Console.WriteLine(System.Text.Encoding.Default.GetString(data)); Console.WriteLine(System.Text.Encoding.Default.GetString(reData)); Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(data)); Assert.AreEqual("hello world", System.Text.Encoding.Default.GetString(reData)); } }
public void TestDnsException() { var connector = new KcpConnector(123, "http://123.0.0.1", 7777); Exception e = null; connector.On(SocketEvents.Error, (ex) => { e = ex as Exception; }); var wait = connector.Connect(); if (!Util.Wait(wait, 10000)) { connector.Dispose(); Assert.Fail("wait faild"); } Assert.AreEqual(typeof(SocketException), (wait.Result as Exception).GetType()); }