熟悉MTK手机平台的看进来!!!
熟悉MTK手机平台的或者熟悉其他手机平台的 DN们。。。。。进来吼下!!!!
[解决办法]
我来了。。。
[解决办法]
求高手指导:我的socket联网解析域名老是连接不了 是MT6235的平台
小弟新手 感激不尽
#include "MMI_features.h"
#include "MMIDataType.h"
#include "gdi_include.h"
#include "wgui.h"
#include "gui.h"
#include "Globaldefs.h"
#include "CustDataRes.h"
#include "gui_themes.h"
#include "wgui_categories.h"
#include "wgui_softkeys.h"
#include "stdC.h"
#include "HistoryGprot.h"
#include "Gdi_include.h"
#include "MainMenuDef.h"
#include "Kal_non_specific_general_types.h"
#include "soc_api.h"
#include "Cbm_api.h"
#include "EventsGprot_Int.h"
#include "ProtocolEvents.h"
kal_char *domain_name= "http://my.gdtel.com";
kal_uint8 val;
kal_int8 socket_id;
kal_int8 ret;
kal_uint8 rcv[100];
kal_uint8 rcv_len = 100;
sockaddr_struct server_ip_addr;
void soctest(void);
void draw( S32 x, S32 y, char *str);
MMI_BOOL soctest_ind(void *inMsg);
MMI_BOOL socket_notify(void *inMsg);
MMI_BOOL soctest_create(void);
MMI_BOOL soctest_gethostbyname(void);
MMI_BOOL soctest_connect(void);
kal_int8 soctest_close(void);
void mmi_enter_eReader()
{
kal_int8 ret = 0;
EntryNewScreen(MAIN_MENU_SCREENID,NULL,NULL,NULL);
soctest();
SetKeyHandler(GoBackHistory, KEY_RSK, KEY_EVENT_UP);
}
void soctest(void)
{
entry_full_screen();
clear_screen();
soctest_create();
soctest_gethostbyname();
soctest_connect();
gui_BLT_double_buffer(0,0,UI_device_width-1,UI_device_height-1);
soctest_close();
}
MMI_BOOL soctest_create(void)
{
socket_id = soc_create(SOC_PF_INET,
SOC_SOCK_STREAM,
0,
MOD_MMI,
14);
printf("\n\n\n Socket_id = %d\n\n\n", &socket_id);
if(socket_id<0) //socket创建失败
{
gui_move_text_cursor(10,10);
gui_print_text(L"Create Fail");
return KAL_FALSE;
}
else//创建OK
{
val = 1;//设置socket模式
soc_setsockopt(socket_id, SOC_NBIO, &val, sizeof(val));
val = SOC_READ | SOC_WRITE | SOC_CLOSE | SOC_CONNECT;
soc_setsockopt(socket_id, SOC_ASYNC, &val, sizeof(val));
gui_move_text_cursor(10,10);
gui_print_text(L"Create OK");
return KAL_TRUE;
}
}
MMI_BOOL soctest_gethostbyname(void)
{
ret = soc_gethostbyname2(KAL_TRUE,
MOD_MMI,
1,//HTTP
(kal_char *)domain_name,
(kal_uint8*)rcv,
(kal_uint8 *)&rcv_len,
0,
14,
0,
NULL);
if(ret == SOC_SUCCESS)
{
memcpy(server_ip_addr.addr, rcv, 4);
server_ip_addr.addr_len = 4;
gui_move_text_cursor(10,60);
gui_print_text(L"Get Host OK");
return KAL_TRUE;
}
else
{
if(ret == SOC_WOULDBLOCK)// 当前函数处于阻塞,等待监听消息MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND的通知函数处理完毕返回
{
gui_move_text_cursor(10,60);
gui_print_text(L"Get Host WOULDBLOCK");
mmi_frm_set_protocol_event_handler(MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND, (PsIntFuncPtr)soctest_ind, MMI_TRUE);
//SetProtocolEventHandler(soctest_ind,MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND);
return KAL_TRUE;
}
else
{
gui_move_text_cursor(10,60);
gui_print_text(L"Get Host Fail");
return KAL_FALSE;
}
}
}
MMI_BOOL soctest_ind(void *inMsg)//get host by name 阻塞等待
{
app_soc_get_host_by_name_ind_struct *dns_ind;
kal_uint8 app_id;
gui_move_text_cursor(10,310);
gui_print_text(L"In soc inds");
if(!inMsg)
{
gui_move_text_cursor(10,90);
gui_print_text(L"inMsg is NULL");
return MMI_FALSE;
}
dns_ind = ( app_soc_get_host_by_name_ind_struct * ) inMsg;
app_id = cbm_get_app_id(dns_ind->account_id);
printf("\n\n\n dns error=%d\n\n\n",&(dns_ind->detail_cause));
printf("\n\n\n account_id= %d\n\n\n", &(dns_ind->account_id));
printf("\n\n\n app_id=%d\n\n\n\n",&app_id);
printf("\n\n\n request=%d\n\n\n", &(dns_ind->request_id));
if( dns_ind->result == KAL_TRUE )
{
memcpy(server_ip_addr.addr, dns_ind->addr, dns_ind->addr_len);
server_ip_addr.addr_len = 4;
gui_move_text_cursor(10,180);
gui_print_text(L"Get Host OK ");
}
else
{
gui_move_text_cursor(10,220);
gui_print_text(L"Get Host Fail");
}
return KAL_TRUE;
}
MMI_BOOL soctest_connect(void)
{
server_ip_addr.sock_type = SOC_SOCK_STREAM;
server_ip_addr.addr_len = 4;
server_ip_addr.addr[0] = 192;
server_ip_addr.addr[1] = 168;
server_ip_addr.addr[2] = 106;
server_ip_addr.addr[3] = 60;
server_ip_addr.port = 80;
ret = soc_connect(socket_id, &server_ip_addr);
if( ret == SOC_SUCCESS )
{
gui_move_text_cursor(10,30);
gui_print_text(L"connect ok");
return KAL_TRUE;
}
else
{
if( ret == SOC_WOULDBLOCK )//异步事件
{
gui_move_text_cursor(10,120);
gui_print_text(L"connect SOC WOULDBLOCK");
mmi_frm_set_protocol_event_handler(MSG_ID_APP_SOC_NOTIFY_IND, (PsIntFuncPtr)socket_notify, MMI_TRUE);
gui_move_text_cursor(10,150);
gui_print_text(L"Notify Over");
return KAL_TRUE;
}
else
{
gui_move_text_cursor(10,120);
gui_print_text(L"connect fail");
return KAL_FALSE;
}
}
}
运行结果如下:
MMI_BOOL socket_notify(void *inMsg)
{
app_soc_notify_ind_struct *soc_notify = (app_soc_notify_ind_struct*) inMsg;
gui_move_text_cursor(10,280);
gui_print_text(L"In soc notify");
printf("\n\n\n notify socket_id = %d", &(soc_notify->socket_id));
if(soc_notify->socket_id != socket_id)
{
return MMI_FALSE;
}
switch (soc_notify->event_type)
{
case SOC_WRITE:
break;
case SOC_READ:
break;
case SOC_CONNECT:
if( soc_notify->result == KAL_TRUE )
{
gui_move_text_cursor(10,250);
gui_print_text(L"CONNECT OK");
//send request
}
else
{
gui_move_text_cursor(10,250);
gui_print_text(L"CONNECT NOT REACHABLE");
}
break;
}
return KAL_TRUE;
}
kal_int8 soctest_close(void)
{
return soc_close(socket_id);
}