[请教]使用open C中的connect方法怎么自动选择接入点?
使用open C中的connect方法怎么自动选择接入点,不弹出选择框?
只有在真机上才会弹出选择节入点。
(可惜这里不能用RConnection,项目要求)
=======================================
strcpy(ifr.ifr_name,"cnwap");
setdefaultif(&ifr);
ioctl(m_Sockfd, SIOCSIFNAME, &ifr);
ioctl(m_Sockfd, SIOCIFSTART, &ifr);
开始我直接用CCommsDatabase取出来的COMMDB_NAME名字给ifr_name不行。
后来用下面代码// 获取节入点信息后面的哪print打印出来发现ifr_name都是乱码。
==========================================
这是我查的参考资料。注意里面的 ([1 Start new] and [2 sub-connection]),
http://discussion.forum.nokia.co ... s-point-for-connect(socket)-with-OpenC&highlight=
==========================================
bool BActive::createConnect()
{
if (m_Sockfd != -1)
{
//为异常断开重新连接
close(m_Sockfd);
}
m_Sockfd = -1;
struct hostent *host;
struct sockaddr_in serv_addr;
strcpy(
m_Url,
"rtsp://192.168.0.205:554/monitor.mp4?cn=ff8080812a3a735b012a3a9ece6b0003&id=hht&en=ca_935c5cbe119e4e6aa79a70c13ceb420d&ph=&c=000&w=0");
char *rtspPtr = strrchr(m_Url, ':');
int iRtspIPLen = rtspPtr - m_Url - strlen("rtsp://");
strncpy(m_TcpIP, m_Url + strlen("rtsp://"), iRtspIPLen);
host = gethostbyname(m_TcpIP);
if (host == NULL)
{
//Global::ShowMessage("get hostbyname 失败...");
return false;
}
m_Sockfd = socket(AF_INET, SOCK_STREAM, 0);
ifreq ifr;
//strcpy(ifr.ifr_name,"Winsock");
strcpy(ifr.ifr_name,"cnwap");
//strcpy(ifr.ifr_name,ifc.ifc_req[1].ifr_name);
setdefaultif(&ifr);
ioctl(m_Sockfd, SIOCSIFNAME, &ifr);
ioctl(m_Sockfd, SIOCIFSTART, &ifr);
if (m_Sockfd == -1)
{
// Global::ShowMessage("建立网络连接失败...");
return false;
}
int nRecvBuf = 60 * 1024;//设置为32K
setsockopt(m_Sockfd, SOL_SOCKET, SO_RCVBUF, (const char*) &nRecvBuf,
sizeof(int));
int nSendBuf = 32 * 1024;//设置为32K
setsockopt(m_Sockfd, SOL_SOCKET, SO_SNDBUF, (const char*) &nSendBuf,
sizeof(int));
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(5000);
serv_addr.sin_addr = *((struct in_addr*) host->h_addr);
//memset(0,8)
bzero(&(serv_addr.sin_zero), 8);
int i = 0;
int sockfd;
struct ifconf ifconf;
char buf[512];
struct ifreq *ifreq;
//初始化ifconf
ifconf.ifc_len = 512;
ifconf.ifc_buf = buf;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
ioctl(sockfd, SIOCGIFCONF, &ifconf); //获取所有接口信息
// 获取节入点信息
// ioctl(m_Sockfd, SIOCGIFINDEX, &ifr);
// printf(" cur name = [%s]\n", ifr.ifr_name);
//接下来一个一个的获取IP地址
//ifreq = (struct ifreq*) buf;
// for (i = (ifconf.ifc_len / sizeof(struct ifreq)); i > 0; i--)
// {
// // if(ifreq->ifr_flags == AF_INET){ //for ipv4
// printf("name = [%s]\n", ifreq->ifr_name);
// printf("name2 = [%s]\n", ifconf.ifc_req.ifr_name);
// printf("local addr = [%s]\n",
// inet_ntoa(((struct sockaddr_in*) &(ifreq->ifr_addr))->sin_addr));
// ifreq++;
// // }
// }
if (connect(m_Sockfd, (struct sockaddr *) &serv_addr, sizeof(serv_addr))
== -1)
{
}
return true;
}
[解决办法]
为什么不使用RSocket?