|
void SocketTest(U8* paBuffer)
{
kal_uint8 val = 1;
kal_int32 nwt_acount_id = 5;
kal_int8 ret;
kal_uint8 addr[4] = {125, 91, 4, 144};
// kal_uint8 addr[4] = {10, 0, 0, 172};
sockaddr_struct server_ip_addr;
kal_int8 socket_id;
/*初始化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);
if (socket_id >= 0)
{
if (soc_setsockopt(socket_id, SOC_NBIO, &val, sizeof(val)) < 0)
{
UCMAIL_AddDebugLog(-1, "Set socket to nonblock mode error !!");
return;
}
val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
if (soc_setsockopt(socket_id, SOC_ASYNC, &val, sizeof(val)) < 0)
{
UCMAIL_AddDebugLog(-1, "Set socket to nonblock mode error !!");
return;
}
}
/*连接Socket*/
server_ip_addr.addr_len = 4;
server_ip_addr.port = 8094;
memcpy(server_ip_addr.addr, addr, 4);
ret = soc_connect(socket_id, &server_ip_addr);
ret = soc_send(socket_id, "GET / HTTP/1.1\r\nHost: 125.91.4.144\r\nConnection: Close\r\n\r\n", 66, 0);
for(nwt_acount_id=0; nwt_acount_id< 0xFFFFFFF; nwt_acount_id++)
{
}
/*仅作试验,实用要加上阻塞判断与数据收取触发等*/
if (ret == 66)
{
ret = soc_recv(socket_id, paBuffer, 256, 0);
}
return;
}
之前有网友通过这段代码,在模拟器上能够联通网络。为什么我用这段代码不行呢。我调试了一下,ret始终都不为66,soc_rev也没有被执行过。 |
|