Hello,
I have a problem with a websocket client that I try to develop. The
connection to the server can be established and I get a confirming
message, but afterwards I can send whatever I want and never get a
response. According to the documentation of the websocket API I send
correct messages and sometimes I even get a response, but most of the
time not.
Its the kraken websocket API, which is behind cloudflare and requires
SNI:
https://docs.kraken.com/websockets/
I have made up a script to isolate the issue. For simplicity I left out
any json parsing/generation. It is best [source]d into a live tclsh:
===== test-ws.tcl script below ===================================
package require tls
package require websocket
::http::register https 443 [list ::tls::socket -autoservername yes]
proc handle {sock type msg} {
puts "received \[$type\] with message \[$msg\]"
switch -- $type {
text {
if {[string match {*"status":"online"*} $msg]} {
global connected
set connected yes
}
}
}
}
set s [websocket::open wss://
ws.kraken.com handle]
vwait connected
websocket::send $s text {{"event":"ping"}}
====== test-ws.tcl script above ==================================
The last line
% websocket::send $s text {{"event":"ping"}}
should lead to a "pong" response on the socket, according to the
documentation
https://docs.kraken.com/websockets/#message-ping
And sometimes I even *do* receive the pong in my now endlessly thousands
of attempts... but most of the time not. Needless to say that it doesn't
make sense to go further and send other messages, when not even a simple
"ping" works.
The [websocket::send] itself does not generate an error. It appears as
if the message could have been sent (number of bytes is the result).
According to the docs, TLS with SNI support is a requirement, and the
servers are behind cloudflare. To my knowledge, the -autoservername flag
in [tls::socket] takes care of SNI, and since it is [http::register]ed,
it should be fine on http level (connection can be established, after
all). But I am not sure whether this extends to the websocket after
upgrade from http... could that be the problem?
Or what else could be the problem? Apart from the server not working,
but I think this is not likely.
BTW, the websocket package works on other wss:// websocket servers, so
websocket and TLS is in general not a problem. Just on this particular
kraken API behind its cloudflare stuff it is.
Thanks in advance,
--
EL