当前位置: 代码迷 >> 移动平台 >> MTK 6225 SOCKET有关问题soc_connect通不过返回-2
  详细解决方案

MTK 6225 SOCKET有关问题soc_connect通不过返回-2

热度:6934   发布时间:2013-02-26 00:00:00.0
MTK 6225 SOCKET问题soc_connect通不过返回-2
#ifdef MMI_ON_HARDWARE_P 
kal_uint8 nwt_acount_id = custom_get_csd_profile_num(); 
#else 
kal_uint8 nwt_acount_id = 14; //CMNET设置为14 
#endif 
kal_uint8 val = 1;
kal_int8 ret;
kal_uint8 addr[4] = {119,147,15,13};
// kal_uint8 addr[4] = {10, 0, 0, 172};
sockaddr_struct server_ip_addr;
  kal_int8 socket_id;
int nLen = 0;
char paBuffer[1024] = {0};

char *rtsp_describe = "rtsp://211.136.165.57:554/699007/16/0/269077349/cjyjsj_3l.3gp;JSESSIONID=%s?msisdn=13701014782&mdspid=cms0001&spid=699007&netType=3&sid=2001817700&pid=2002218100&timestamp=20100119190732&Channel_ID=0&ProgramID=2645847&ParentNodeID=52784&encrypt=1e715e40182364a46b467b23c63e63da RTSP/1.0\r\n\
CSeq: 1\r\n\
Accept: application/sdp\r\n\
User-Agent: VLC Media Player (LIVE.COM Streaming Media v2004.11.11)\r\n\r\n";
sprintf(paBuffer, rtsp_describe, sessionId);

//初始化Soc
#ifndef MMI_ON_HARDWARE_P 
soc_init_win32(); 
#endif 
// 创建Socket
socket_id = soc_create(PF_INET, SOCK_STREAM, 0, MOD_MMI, nwt_acount_id);//always_ask_encode_data_account_id(nwt_acount_id, 1, 0, 0));

  if (socket_id >= 0)
  {
  if (soc_setsockopt(socket_id, SOC_NBIO, &val, sizeof(val)) < 0)
  {
  return;
  }
  val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
  if (soc_setsockopt(socket_id, SOC_ASYNC, &val, sizeof(val)) < 0)
  {
  return;
  }
  } 

// rtsp://211.136.165.57/699007/16/0/269077349/cjyjsj_3l.3gp?
// msisdn=13701014782&mdspid=cms0001&spid=699007&netType=3
// &sid=2001817700&pid=2002218100&timestamp=20100119190732
// &Channel_ID=0&ProgramID=2645847&ParentNodeID=52784
// &encrypt=1e715e40182364a46b467b23c63e63da

//*连接Socket
if (socket_id < 0)
{
char* pstrTemp = "error:soc_create\n";
fone_mmi_write_logfile(pstrTemp, strlen(pstrTemp));
return;
}

server_ip_addr.addr_len = 4;
server_ip_addr.port = 80;
server_ip_addr.sock_type = SOCK_STREAM; 
memcpy(server_ip_addr.addr, addr, 4);
/*
{
char strTemp[100] = {0}; 
sprintf(strTemp, "socket:%d addr list:%d.%d.%d.%d:%d\n",
socket_id,
server_ip_addr.addr[0],
server_ip_addr.addr[1],
server_ip_addr.addr[2],
server_ip_addr.addr[3],
server_ip_addr.port);
fone_mmi_write_logfile(strTemp, strlen(strTemp));
}
*/
ret = soc_connect(socket_id, &server_ip_addr);//这里说什么也过不去了。

if (ret < 0)
{
char strTemp[100] = {0}; 
sprintf(strTemp, "soc_connect error:%d\n", ret);
fone_mmi_write_logfile(strTemp, strlen(strTemp));
return;
}
  ret = soc_send(socket_id, (kal_uint8*)paBuffer, sizeof(paBuffer), 0);
if (ret <= 0)
{
char strTemp[100] = {0}; 
sprintf(strTemp, "soc_send error:%d\n", ret);
fone_mmi_write_logfile(strTemp, strlen(strTemp));
return;
}
fone_mmi_write_logfile(paBuffer, strlen(paBuffer));


memset(paBuffer, 0, 1024);
nLen = soc_recv(socket_id, (kal_uint8*)paBuffer, 1023, 0);
{
fone_mmi_write_logfile(paBuffer, nLen);
memset(paBuffer, 0, 1024);
}
soc_close(socket_id);
return;

------解决方案--------------------------------------------------------
返回-2是肯定的,非阻塞当然是返回-2,当连接成功的消息来了之后,会调用你的回调函数。
  相关解决方案