ASTERSIK C++ 5038
来源:互联网 发布:淘宝退货超过七天 编辑:程序博客网 时间:2024/06/05 17:21
编写Asterisk事件监控程序
原理:通过login action连上Asterisk的5038端口,监听此端口并把消息输出。
下面是C++实现的代码:
1 /* 2 File : asteriskEventCat.cpp 3 Author : Mike 4 E-Mail : Mike_Zhang@live.com 5 */ 6 7 #include <iostream> 8 #include <string> 9 #include <fstream>10 #include <boost/asio.hpp>11 #define BLOCK_SIZE 10*102412 13 using namespace std;14 using namespace boost::asio;15 16 string strLogin(string userName,string pswwd)17 {18 string msg="";19 msg = "Action: login\r\n";20 msg += "UserName: " + userName + "\r\n";21 msg += "Secret: " + pswwd + "\r\n";22 msg += "\r\n"; 23 return msg;24 }25 26 int main()27 {28 io_service iosv;29 ip::tcp::socket s(iosv);30 string svrIp = "";31 cout<<"Input server ip : ";32 cin>>svrIp;33 ip::tcp::endpoint ep(ip::address_v4::from_string(svrIp.c_str()),5038);34 35 boost::system::error_code ec; 36 s.connect(ep,ec); 37 if(ec)38 {39 cout << boost::system::system_error(ec).what() << endl; 40 return -1; 41 } 42 else43 {44 cout<<"Connect success!"<<endl;45 }46 47 string msg="";48 49 string userName,password;50 cout<<"User : ";51 cin>>userName;52 cout<<"Password : ";53 cin>>password;54 55 msg += strLogin(userName.c_str(),password.c_str());56 // msg += strLogin("admin","admin");57 size_t len = s.write_some(buffer(msg.c_str()), ec);58 if(len <= 0)59 {60 cout<<"Send message fail!"<<endl;61 return -1;62 }63 64 std::ofstream fout("EventCat.txt");65 while(true)66 {67 char buf[BLOCK_SIZE] = {0};68 len=s.read_some(buffer(buf), ec); 69 if(len<=0)70 break;71 cout.write(buf, len); 72 fout<<buf;73 fout.flush();74 } 75 76 return 0;77 }
- ASTERSIK C++ 5038
- astersik bridge 支持
- Astersik呼叫流程 详细
- Astersik Channel Analysis
- Astersik 遇到的问题及解决 (一)
- c
- c
- c
- c
- C
- c
- c
- c
- C+
- c
- C
- c
- c
- AS3数字取整
- Mock in Test
- shell中的exit 1 && exit 0
- winform限制软件次数
- 怎么写linux usb驱动
- ASTERSIK C++ 5038
- JAVA遍历文件夹(多层)下的所有文件,批量修改文件名
- boost中bind的使用
- 爱上安静、沉默,习惯了一个人
- arcserver10.1管理密码重置
- discuz在后台 应用 应用中心 安装一个dz 2.5模板 显示超时无法安装模板
- 关于ListView的Adapter,解决ListView滚动后内容重复的问题
- tomcat报错,该怎么解决呢?
- truncate 于delete的区别