Posted to tcl by nektomk at Wed Sep 09 14:47:09 GMT 2020view raw

  1. # bug inside tcllib websocket or http ???
  2.  
  3. package require http
  4. package require websocket
  5.  
  6. package require tls
  7. http::register https 443 [ list tls::socket -autoservername true ]
  8. http::register wss 443 [ list tls::socket -autoservername true ]
  9.  
  10. ### twapi also shows this bug
  11. #package require twapi
  12. #package require twapi_crypto
  13. #http::register https 443 [ list twapi::tls_socket ]
  14. #http::register wss 443 [ list twapi::tls_socket ]
  15.  
  16. # enable logging
  17. websocket::loglevel debug
  18. proc http::Log {args} {::puts "http>> $args"}
  19.  
  20. # handler for websocket
  21. proc handler { sock ev msg } {
  22. puts "-------- got message $ev: $msg ----------"
  23. if { $ev == "connect" } {
  24. puts "VISTORY !!!!!!!!!!!!!!"
  25. }
  26. if { $ev == "timeout" } {
  27. puts "timeout :-("
  28. }
  29. if { $ev == "disconnect" } {
  30. puts "disconnect :-("
  31. }
  32. exit
  33. }
  34.  
  35. # this URL not open via tcl`websocket::open (stalled under http, after "^D receiving message")
  36. websocket::open wss://fstream.binance.com/stream?streams=!bookTicker handler -timeout 20000
  37.  
  38. # but this: wss://stream.binance.com:9443/stream?streams=!bookTicker
  39. # correct
  40. # and this (undocumented in binance) wss://stream.binance.com/stream?streams=!bookTicker
  41. #
  42. # official doc see https://binance-docs.github.io/apidocs/futures/en/#websocket-market-streams
  43.  
  44. # but all 3 url`s may opens via `wscat --connect $url` in linux
  45. # or inside web-service "https://www.websocket.in/test-online#" and others
  46.  
  47. vwait the_end
  48.  

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.