Hello Jonte,
thanks for the quick reply.
Make sure you’re using wss://testnet.binance.vision
as the Websocket URL for testnet.
However, my problem is still before the direct connection to the websocket.
If the sequence is correct TCP → TLS → websocket, my connection hangs at the TLS handshake.
I am using C programming language with libssl (3.0.2):
(only the crucial steps)
// DNS to get IP
if( (host = gethostbyname(“testnet.binance.vision”)) == NULL){ printf(“ERROR gethostbyname()\n”);}
ip_ptr = (struct in_addr **)host->h_addr_list;
// set SSL context
if( (mein_ctx = SSL_CTX_new_ex(NULL,NULL,TLS_client_method())) == 0 ){ printf(“Error SSL_CTX_new()\n”); exit(1);}
// normaly TLS 1_3 but stream.binance.com:9443 dont work with TLS 1_3
if( !SSL_CTX_set_max_proto_version(mein_ctx,TLS1_2_VERSION) ){ printf(“Fehler bei SSL_CTX_set_min_proto_version()\n”);}
// set SSL object
if( (mein_ssl = SSL_new(mein_ctx)) == 0 ){ printf(“Fehler bei ssl_new\n”); exit(1);}
// create socket
if( (c_socket = socket(AF_INET, SOCK_STREAM, 0)) <= 0){ printf(“Fehler bei socket()\n”); exit(1);}
address.sin_family = AF_INET;
address.sin_port = htons(443);
inet_aton(ip_zeiger,&address.sin_addr);
// connect TCP
if( (connect( c_socket, (struct sockaddr *) &address, sizeof(address)) != 0)){ printf(“Fehler bei connect tcp\n”); exit(1);}
else{ printf(“connection ok\n”);}
// set socket to SSL object and connect
if( SSL_set_fd(mein_ssl, c_socket) > 1 ){ printf(“Fehler bei set_fd()\n”); exit(1);}
if( (conn = SSL_connect(mein_ssl)) == 0 ){ printf(“cracefull SSL shutdown\n”); exit(1);}
else if( conn < 0){ printf(“SSL bad shutdown: %i\n”,conn);
error = SSL_get_error(mein_ssl,conn);
printf(“error: %i\n”,error);
}