Open sci-ripper opened 1 year ago
#include <libwebsockets.h>
#include <string.h>
#include <sys/time.h>
#define EXAMPLE_RX_BUFFER_BYTES (100)
static struct lws *web_socket = NULL;
static int callback_example(struct lws *wsi, enum lws_callback_reasons reason,
void *user, void *in, size_t len)
{
// Add your callback handling code here
return 0;
}
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;
// Additional SSL options or certificate handling can be added here if needed
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;
}
Hi, I'm trying to connect to IBM Watson Text to Speech API's Websocket using libwebsockets. I based my code on a simple websocket client found on iamscottmoyers / simple-libwebsockets-example / client.c. I added support for SSL but I'm getting the following TLS error:
My code is as follows:
Thanks in advance!