public bahaCash(TcpClient client) { //check ip address this.client = client; splitstring = client.Client.RemoteEndPoint.ToString().Split('.'); clientip = splitstring[0] + splitstring[1] + splitstring[2]; if (clientip == bahaip){ string time = Util.getTime(); Console.WriteLine("\nCorrect Connected" + time + "!{0} <-- {1}", client.Client.LocalEndPoint, client.Client.RemoteEndPoint); streamToClient = client.GetStream(); buffer = new byte[BufferSize]; handler = new RequestHandler(); AsyncCallback callBack = new AsyncCallback(ReadComplete); streamToClient.BeginRead(buffer, 0, BufferSize, callBack, null); //r }else{ string time = Util.getTime(); Console.WriteLine("\nWrong Connected" + time + "!{0} <-- {1}" + "_" + clientip, client.Client.LocalEndPoint, client.Client.RemoteEndPoint); client.Close(); } }
public static void Test() { RequestHandler handler = new RequestHandler(); string input; // 第一种情况测试 - 一条消息完整发送 input = "[length=13]明天中秋,祝大家节日快乐!"; handler.PrintOutput(input); // 第二种情况测试 - 两条完整消息一次发送 input = "明天中秋,祝大家节日快乐!"; input = String.Format ("[length=13]{0}[length=13]{0}", input); handler.PrintOutput(input); // 第三种情况测试A - 两条消息不完整发送 input = "[length=13]明天中秋,祝大家节日快乐![length=13]明天中秋"; handler.PrintOutput(input); input = ",祝大家节日快乐!"; handler.PrintOutput(input); // 第三种情况测试B - 两条消息不完整发送 input = "[length=13]明天中秋,祝大家"; handler.PrintOutput(input); input = "节日快乐![length=13]明天中秋,祝大家节日快乐!"; handler.PrintOutput(input); // 第四种情况测试 - 元数据不完整 input = "[leng"; handler.PrintOutput(input); // 不会有输出 input = "th=13]明天中秋,祝大家节日快乐!"; handler.PrintOutput(input); }