日期:2014-05-18 浏览次数:20994 次
namespace ConsoleApplication1 { class Program { public static string ly_mc_0 = "";//通道1名称 public static string ly_mc_1 = "";//通道2名称 public delegate void p_MyPhonicCallBack(PhonicDLL.EPhonicEvent eventType, int channelType, int channelID, int iParam1, int iParam2);// 定义委托 p_MyPhonicCallBack pdataRec = new p_MyPhonicCallBack(MyPhonicCallBack); public static void MyPhonicCallBack( PhonicDLL.EPhonicEvent eventType, int channelType, int channelID, int iParam1, int iParam2) { } static void Main(string[] args) { try { [color=#FF0000]PhonicDLL.tpi_SetEventNotifyCallBackProc(pdataRec);[/color] PhonicDLL.tpi_OpenDevice(); string receiveStr = ""; // 把IP地址转换为IPAddress的实例 //IPAddress ipAd = IPAddress.Parse("10.53.32.252"); IPAddress ipAd = IPAddress.Parse("192.168.1.104"); // 初始化监听器, 端口为8008 TcpListener myList = new TcpListener(ipAd, 8888); // 开始监听服务器端口 myList.Start(); while(true) { //测试加的,防止板卡自己关闭/// PhonicDLL.tpi_GetCardCount(1); //测试加的,防止板卡自己关闭/// receiveStr = ""; // 输出服务器启动信息 Console.WriteLine("在8888端口启动服务..."); Console.WriteLine("本地节点为:" + myList.LocalEndpoint); Console.WriteLine("等待连接....."); // 等待处理接入连接请求 // 新建立的连接用套接字s表示 Socket s = myList.AcceptSocket(); Console.WriteLine("连接来自 " + s.RemoteEndPoint); // 接收客户端信息 byte[] b = new byte[100]; int k = s.Receive(b); Console.WriteLine("已接收..."); for (int i = 0; i < k; i++) { receiveStr += Convert.ToChar(b[i]); // Console.Write(Convert.ToChar(b[i])); } Console.WriteLine("命令 " + receiveStr); ////////////////处理电话部分begin/////////////// //指令格式 操作类型(1:拨号 0:挂断)|ChannelType|GetChannelID|电话号码|录音文件名 if (receiveStr != "") { string[] arr = receiveStr.Split('|'); } else { ASCIIEncoding asen = new ASCIIEncoding(); s.Send(asen.GetBytes("-1")); Console.WriteLine("\n已发送回应信息"); // 善后工作,释放资源 s.Close(); } /////////////////处理电话部分end///////////// // 处理客户端请求,给客户端回应 } myList.Stop(); } catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace); } } } }