You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复libwebsockets连接IBM Watson TTS的CLIENT_CONNECTION_ERROR TLS错误

使用libwebsockets连接IBM Watson文本转语音WebSocket时的TLS错误

我尝试使用libwebsockets连接IBM Watson文本转语音API的WebSocket,代码基于一个简易WebSocket客户端实现。添加SSL支持后,出现了如下TLS错误:

[2023/05/19 17:25:09:1697] N: lws_create_context: LWS: 4.3.2-unknown, NET CLI SRV H1 H2 WS ConMon IPv6-absent
[2023/05/19 17:25:09:1767] N: __lws_lc_tag: ++ [wsi|0|pipe] (1)
[2023/05/19 17:25:09:1867] N: __lws_lc_tag: ++ [vh|0|default||-1] (1)
[2023/05/19 17:25:09:2017] N: lws_plat_vhost_tls_client_ctx_init: Imported 46 certs from plat store
[2023/05/19 17:25:09:2067] N: __lws_lc_tag: ++ [wsicli|0|WS/h1/default/api.eu-gb.text-to-speech.watson.cloud.] (1)
[2023/05/19 17:25:09:2957] W: lws_plat_set_socket_options_ip: not implemented on windows platform
[2023/05/19 17:25:09:3377] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:09:3507] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:09:3547] E: CLIENT_CONNECTION_ERROR: tls: error:00000001:lib(0):func(0):reason(1)
[2023/05/19 17:25:09:3607] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:09:3637] N: __lws_lc_untag: -- [wsicli|0|WS/h1/default/api.eu-gb.text-to-speech.watson.cloud.] (0) 157.014ms
[2023/05/19 17:25:14:1987] N: __lws_lc_tag: ++ [wsicli|1|WS/h1/default/api.eu-gb.text-to-speech.watson.cloud.] (1)
[2023/05/19 17:25:14:2907] W: lws_plat_set_socket_options_ip: not implemented on windows platform
[2023/05/19 17:25:14:3237] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:14:3367] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:14:3397] E: CLIENT_CONNECTION_ERROR: tls: error:00000001:lib(0):func(0):reason(1)
[2023/05/19 17:25:14:3447] N: lws_gate_accepts: on = 0
[2023/05/19 17:25:14:3477] N: __lws_lc_untag: -- [wsicli|1|WS/h1/default/api.eu-gb.text-to-speech.watson.cloud.] (0) 149.018ms

我的代码如下:

static struct lws_protocols protocols[] =
{
    {
        "wss",
        callback_example,
        0,
        EXAMPLE_RX_BUFFER_BYTES,
    },
    { NULL, NULL, 0, 0 } /* terminator */
};

int main( int argc, char *argv[] )
{
    struct lws_context_creation_info info;
    memset( &info, 0, sizeof(info) );

    info.port = CONTEXT_PORT_NO_LISTEN;
    info.protocols = protocols;
    info.options = LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT;
    info.gid = -1;
    info.uid = -1;

    struct lws_context *context = lws_create_context( &info );

    time_t old = 0;
    while( 1 )
    {
        struct timeval tv;
        gettimeofday( &tv, NULL );

        /* Connect if we are not connected to the server. */
        if( !web_socket && tv.tv_sec != old )
        {
            struct lws_client_connect_info ccinfo = {0};
            ccinfo.context = context;
            ccinfo.port = 443;
            ccinfo.address = "api.eu-gb.text-to-speech.watson.cloud.ibm.com";
            ccinfo.path = "/instances/{instance_id}/v1/synthesize?access_token={access_token}&voice=en-US_AllisonV3Voice";
            ccinfo.host = lws_canonical_hostname( context );
            ccinfo.origin = "origin";
            ccinfo.protocol = protocols[0].name;
            ccinfo.ssl_connection   = LCCSCF_USE_SSL | LCCSCF_PIPELINE;
            web_socket = lws_client_connect_via_info(&ccinfo);
        }

        if( tv.tv_sec != old )
        {
            /* Send a random number to the server every second. */
            lws_callback_on_writable( web_socket );
            old = tv.tv_sec;
        }

        lws_service( context, /* timeout_ms = */ 250 );
    }

    lws_context_destroy( context );

    return 0;
}

补充说明:我在Windows 11系统上使用MSYS2(MinGW)环境。

内容的提问来源于stack exchange,提问作者Paiku Han

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 20:45:01