Posted to tcl by nektomk at Wed Sep 09 14:47:09 GMT 2020view raw
- # bug inside tcllib websocket or http ???
- package require http
- package require websocket
- package require tls
- http::register https 443 [ list tls::socket -autoservername true ]
- http::register wss 443 [ list tls::socket -autoservername true ]
- ### twapi also shows this bug
- #package require twapi
- #package require twapi_crypto
- #http::register https 443 [ list twapi::tls_socket ]
- #http::register wss 443 [ list twapi::tls_socket ]
- # enable logging
- websocket::loglevel debug
- proc http::Log {args} {::puts "http>> $args"}
- # handler for websocket
- proc handler { sock ev msg } {
- puts "-------- got message $ev: $msg ----------"
- if { $ev == "connect" } {
- puts "VISTORY !!!!!!!!!!!!!!"
- }
- if { $ev == "timeout" } {
- puts "timeout :-("
- }
- if { $ev == "disconnect" } {
- puts "disconnect :-("
- }
- exit
- }
- # this URL not open via tcl`websocket::open (stalled under http, after "^D receiving message")
- websocket::open wss://fstream.binance.com/stream?streams=!bookTicker handler -timeout 20000
- # but this: wss://stream.binance.com:9443/stream?streams=!bookTicker
- # correct
- # and this (undocumented in binance) wss://stream.binance.com/stream?streams=!bookTicker
- #
- # official doc see https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams
- # but all 3 url`s may opens via `wscat --connect $url` in linux
- # or inside web-service "https://www.websocket.in/test-online#" and others
- vwait the_end
Comments
Posted by nektomk at Wed Sep 09 21:37:23 GMT 2020 [text] [code]
I think this is because websocket replaces "wss" with "https" inside the procedure. Without this replacement, the connection will be incorrectly initialized (via core http), and with the replacement, the receiving side will incorrectly address the request.