|
小弟这两天在调试MTK SOCKET连接,但是怎么都连接不上,代码接口如下:
#if 1
#include "soc_consts.h"
#include "soc_api.h"
sockaddr_struct my_ip_addr;
//#define URL0 "POST / HTTP/1.1\r\nX-Online-Host:http://wap.ucweb.com:80\r\nKeep-Alive:close\r\nContent-Length:3\r\n\r\nabc"
//#define URL0 "POST /mvc HTTP/1.0\r\nAccept: text/xml, application/xml,application/xhtml+xml,text/html,text/plain,image/png,*/*\r\nAccept-Language:zh-tw,en-us,en\r\nAccept-Encoding:gzip, deflate\r\nUser-Agent: Mozilla/4.0\r\nContent-Type:application/x-www-form-urlencoded\r\nHost:222.66.42.154:80Content-Length:404\r\nKeep-Alive:300\r\nConnection:Keep-Alive\r\n\r\nServ_ID=S0001&Ver=1.0&Tx_ID=T0003&Receiver=13812341234"
//#define URL1 "GET http://www.google.cn HTTP/1.1\r\nHost: www.google.cn\r\nProxy-Connection: Keep-Alive\r\n\r\n"
#define URL "GET /lenovo/data/mobile/test_zlib/contents.meta HTTP/1.1\\nX-ONLINE-HOST:221.223.53.34:80\\n\\r\\n"
static kal_int8 soc_id;
void my_socket_receive(void);
void my_socket_notify(void *msg_ptr);
void my_socket_send(void)
{
kal_int32 ret;
ret = soc_send(soc_id, (unsigned char*)URL, strlen(URL), 0);
//kal_prompt_trace(MOD_TCPIP," <<<<<<<- %d >>>>>>>>", strlen(URL));
if( ret > 0)
{
my_socket_receive();
}
else
{
SetProtocolEventHandler(my_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
}
}
#define BUF_SIZE 200
void my_socket_receive(void)
{
kal_uint8 rbuf[BUF_SIZE];
int ret;
unsigned short wBuf[BUF_SIZE+1];
ret = soc_recv( soc_id, rbuf, BUF_SIZE, 0);
if( ret > 0)
{
int i;
//kal_prompt_trace(MOD_TCPIP," <<<<<<<- %d >>>>>>>>", rbuf);
if( ret == SOC_WOULDBLOCK)
{
SetProtocolEventHandler(my_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
}
}
}
void my_socket_notify(void *msg_ptr)
{
app_soc_notify_ind_struct *soc_notify = (app_soc_notify_ind_struct *)msg_ptr;
switch(soc_notify->event_type)
{
case SOC_READ:
my_socket_receive();
break;
case SOC_WRITE:
my_socket_send();
break;
case SOC_CONNECT:
//kal_prompt_trace(MOD_TCPIP," <<<<<<<<<<CONNECT>>>>>>>>");
my_socket_send();
break;
case SOC_CLOSE:
break;
default:
break;
}
}
int my_test_socket_entry()
{
kal_uint8 val=KAL_TRUE;
kal_int8 soc_ret;
//kal_int8 soc_id;
soc_id = soc_create(PF_INET, SOCK_STREAM, 0, MOD_MMI, 14); //14); //TPC_ACCOUNT_ID);
if( soc_id < 0)
return 0;
if(soc_setsockopt(soc_id, SOC_NBIO, &val, sizeof(val)) <0)
{
return 0;
}
val=SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
if(soc_setsockopt(soc_id, SOC_ASYNC, &val, sizeof(val)) <0)
{
return 0;
}
memset( &my_ip_addr, 0, sizeof(sockaddr_struct));
my_ip_addr.addr[0] = 10; //10;
my_ip_addr.addr[1] = 0; //0;
my_ip_addr.addr[2] = 0; //0;
my_ip_addr.addr[3] = 172; //172;
my_ip_addr.addr_len = 4;
my_ip_addr.port = 80;
my_ip_addr.sock_type = SOCK_STREAM;
soc_ret = soc_connect(soc_id, &my_ip_addr);
if( soc_ret >= 0)
{
my_socket_send();
return soc_ret;
}else if( soc_ret == SOC_WOULDBLOCK) /* 一般此条件都会成立,返回! */
{
//Jx_debug("SOC_WOULDBLOCK!!!\r\n");
SetProtocolEventHandler(my_socket_notify, MSG_ID_APP_SOC_NOTIFY_IND);
return soc_ret;
}
return 1;
}
#endif
直接调用my_test_socket_entry();但是始终在send时返回-12,发不出东西。
这个 my_socket_notify()函数里面CONNECT是响应的,但是发送就是返回-12.
请哪位高手做过SOCKET的指导下。非常感谢! QQ:32057067 |
|