Alignment with the server my coworkers, my device for the mobile platform, and server communication udp way, use IP connect directly, and then send the data, the server can receive, with the domain name, resolved to send data to the server has not received, don't know what the reason, hope everybody to give directions
Is described in detail as follows:
1. The DNS is mobile platform with interface, parse the IP no problem resulting from the domain name, as well as the direct IP and port
2. The bind is successful and soc_sendto return values consistent with the data length
3. Preach IP connection process is: the IP to parse, returns success directly, and then bind, send_to and server to receive
4. Preach domain connection process is: the domain name to parse, asynchronous waiting for parsing, parsing is successful, the bind, send_to server has not received
Code is as follows, for the sake of concise and easy to see, I cut into the most compact model, the local variable declaration and fault-tolerant code removed, added some description
Void _GetHostByNameReq (U32 acctId, int request_id, S8 * hostName, IP [], U8 under-16 dstPort, U8 access_id)
{
//incoming the hostName for the direct IP or domain name, IP [] for storing parsed get IP global arrays, the following addr for local variables, the resolved IP endures addr
Result=soc_gethostbyname (0, MOD_MMI, request_id, hostName, (U8 *) addr, (U8 *) & amp; Addr_len access_id, acctId);
If (result==SOC_SUCCESS)/* the hostName to IP, will return SOC_SUCCESS */
{
Memcpy (IP addr, MAX_SOCK_ADDR_LEN);
Result=udp_socket_connect (socket id, (U8 *) addr, dstPort);
}
Else if (result==SOC_WOULDBLOCK | | result==SOC_ALREADY)
{
/* the hostName for the domain name, returns SOC_WOULDBLOCK, asynchronous pending resolution */
SetProtocolEventHandler (_GetHostByNameRsp MSG_ID_APP_SOC_GET_HOST_BY_NAME_IND);
}
}
Void _GetHostByNameRsp (void * inMsg)
{
InMsg app_soc_get_host_by_name_ind_struct * pMsg=(app_soc_get_host_by_name_ind_struct *);
If (pMsg & amp; & PMsg - & gt; The result!=FALSE)
{
//asynchronous get resolved IP, endures udp_soc_context. IpAddr
Memcpy (udp_soc_context ipAddr, pMsg - & gt; Addr, pMsg - & gt; Addr_len);
Result=udp_socket_connect (udp_soc_context socId, udp_soc_context ipAddr, udp_soc_context. DstPort);
}
}
Kal_int32 udp_socket_connect (kal_int8 socketId, U8 IP [], under-16 port)
{
Sockaddr_struct addr.
Memcpy (addr. Addr, IP addr. Addr_len);
Addr. The port=port;
Addr. Addr_len=4;
If (socketId==udp_soc_context. SocId)
{
Addr. Sock_type=SOC_SOCK_DGRAM;
Ret=soc_bind (udp_soc_context socId, & amp; Addr);//bind
If (ret==SOC_SUCCESS)
{
Udp_send_test ();//send data
}
}
}
Void udp_send_test (void)
{
Sockaddr_struct server_addr;
Int ret.
U8 * send_buff="hello";
Server_addr. Port=udp_soc_context. DstPort;
Server_addr. Addr_len=4;
Server_addr. Sock_type=SOC_SOCK_DGRAM;
//direct or domain name, the last is send from here, as well as the data print out two ways of server_addr, even server IP and port, but the domain name has been not receive
Ret=soc_sendto (udp_soc_context socId, (kal_uint8 *) send_buff, sizeof (send_buff), 0, & amp; Server_addr);
The StartTimer (UDP_TIMER_ID_OBD, 8000, udp_send_test);//every 8 seconds to send data to the server
}
CodePudding user response:
I lost, I top, looking forward to the great god