|
void UDP_send_test(void)
{
sockaddr_struct server_addr;
int ret;
U8 send_buff[]="helloworld";
server_addr.addr[0] = 212;
server_addr.addr[1] = 220;
server_addr.addr[2] = 124;
server_addr.addr[3] = 103;
server_addr.port = 5963;
server_addr.addr_len = 4;
server_addr.sock_type = SOC_SOCK_DGRAM;
ret = soc_sendto(g_udp_soc_context.socId,(kal_uint8*)send_buff,sizeof(send_buff),0, &server_addr);
if(ret == SOC_WOULDBLOCK)
{
SetProtocolEventHandler(udp_socketNotify, MSG_ID_APP_SOC_NOTIFY_IND);
}
StartTimer(UDP_SEND_TIMER, 10 * 1000, UDP_send_test);
}
kal_int8 UDP_SocketConnect(void)
{
kal_int8 ret = 0;
sockaddr_struct server_addr;
server_addr.addr[0] = 212;
server_addr.addr[1] = 220;
server_addr.addr[2] = 124;
server_addr.addr[3] = 103;
server_addr.port = 5963;
server_addr.addr_len = 4;
server_addr.sock_type = SOC_SOCK_DGRAM;
ret = soc_bind(g_udp_soc_context.socId, &server_addr);
if(ret == SOC_WOULDBLOCK || ret == SOC_SUCCESS)
{
SetProtocolEventHandler(udp_socketNotify, MSG_ID_APP_SOC_NOTIFY_IND);
if (ret == SOC_SUCCESS)
{
//
}
}
UDP_send_test();
}
我这是mtk60平台,socket创建成功了,但是发消息服务器收不到,soc_bind 返回值为0,bind是成功的,然后每10s MTK60发一次udp消息给服务器,soc_sendto返回值为11,服务器几乎一直收不到,有时候在MTK60开机时能收到2个包,然后以后一直收不到!发送的ip和端口是服务器那边直接给我的,请高手指点! |
|