0
jesse

Hi
我依照AN0033的說明,嘗試用SDK3.5的OTA HTTP example 更新firmware,但是總是會出現
[update_ota_http_connect_server] Socket connect failed
[http_update_ota_task] Update task exit
沒辦法連上我執行DownloadServer的PC
請問這應該是什麼樣的問題?

//原始的server_addr.sin_addr.s_addr
//memcpy(&server_addr.sin_addr.s_addr,server->h_addr,server->h_length);

//修改為下方,依然是連不上
server_addr.sin_addr.s_addr = inet_addr(host);

 

int update_ota_http_connect_server(int server_socket, char *host, int port){
struct sockaddr_in server_addr;
struct hostent *server;
server_socket = socket(AF_INET, SOCK_STREAM, 0);
if(server_socket < 0){
printf("\n\r[%s] Create socket failed", __FUNCTION__);
return -1;
}

server = gethostbyname(host);
if(server == NULL)
printf("[ERROR] Get host ip failed\n");

memset(&server_addr,0,sizeof(server_addr));
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(port);
//memcpy(&server_addr.sin_addr.s_addr,server->h_addr,server->h_length);

server_addr.sin_addr.s_addr = inet_addr(host);

if (connect(server_socket,(struct sockaddr *)&server_addr, sizeof(server_addr)) < 0){
printf("\n\r[%s] Socket connect failed", __FUNCTION__);

return -1;
}

return server_socket;
}

sean 回答了