src/tcp_client.c
//use this esp32 as a tcp client. return ESP_OK:success ESP_FAIL:error
use this esp32 as a tcp client.
use this esp32 as a tcp client .
esp_err_t create_tcp_client()
{
    ESP_LOGI(TAG, "client socket....serverip:port=%s:%d\n",
             EXAMPLE_DEFAULT_SERVER_IP, EXAMPLE_DEFAULT_PORT);
    connect_socket = socket(AF_INET, SOCK_STREAM, 0);
    if (connect_socket < 0) {
        show_socket_error_reason("create client", connect_socket);
        return ESP_FAIL;
    }
    server_addr.sin_family = AF_INET;
    server_addr.sin_port = htons(EXAMPLE_DEFAULT_PORT);
    server_addr.sin_addr.s_addr = inet_addr(EXAMPLE_DEFAULT_SERVER_IP);
    ESP_LOGI(TAG, "connecting to server...");
    if (connect(connect_socket, (struct sockaddr *)&server_addr, sizeof(server_addr)) < 0) {
        show_socket_error_reason("client connect", connect_socket);
        return ESP_FAIL;
    }
    ESP_LOGI(TAG, "connect to server success!");
    return ESP_OK;
}
esp_err_t create_tcp_client ( ) { ESP_LOGI ( TAG , " \n " , EXAMPLE_DEFAULT_SERVER_IP , EXAMPLE_DEFAULT_PORT ) ; connect_socket = socket ( AF_INET , SOCK_STREAM , 0 ) ; if ( connect_socket < 0 ) { show_socket_error_reason ( " " , connect_socket ) ; return ESP_FAIL ; } server_addr . sin_family = AF_INET ; server_addr . sin_port = htons ( EXAMPLE_DEFAULT_PORT ) ; server_addr . sin_addr . s_addr = inet_addr ( EXAMPLE_DEFAULT_SERVER_IP ) ; ESP_LOGI ( TAG , " " ) ; if ( connect ( connect_socket , ( struct sockaddr * ) & server_addr , sizeof ( server_addr ) ) < 0 ) { show_socket_error_reason ( " " , connect_socket ) ; return ESP_FAIL ; } ESP_LOGI ( TAG , " " ) ; return ESP_OK ; }
use this esp32 as a tcp client.
use this esp32 as a tcp client .