Hi Gustaf,
I’ve noticed you had uploaded a simple client interface to
websocket-procs.tcl.
https://bitbucket.org/naviserver/websocket/src/master/websocket-procs.tcl
<https://bitbucket.org/naviserver/websocket/src/master/websocket-procs.tcl>
However, I hit another error related to [dict], because the url doesn’t return
a path, when [dict get $d path] runs.
The websocket sample is "wss://javascript.info/article/websocket/demo/hello"
Best wishes,
I
[12/Jul/2020:21:03:33][22342.7efbf37fe700][-conn:iurix:0:36-] Error: can't read
"path": no such variable
while executing
"append request_url /$path"
(procedure "ws::client::open" line 19)
invoked from within
"ws::client::open $url"
("uplevel" body line 8)
invoked from within
"uplevel {
ns_log Notice "Running TCL script luna.tcl"
#set url
"ws://192.199.241.130:5008/api/subscribe?auth_token=9fb6e731-b342-4952-b0c1-aa1d0..."
(procedure "code::tcl::/var/www/iurix//packages/ix-websocket/www/luna" line
2)
invoked from within
"code::tcl::$__adp_stub"
("uplevel" body line 12)
invoked from within
"uplevel {
if { [file exists $__adp_stub.tcl] } {
# ensure that data source preparation procedure exists and is
up-to-date
..."
(procedure "adp_prepare" line 2)
invoked from within
"adp_prepare"
invoked from within
"template::adp_parse $themed_template {}"
(procedure "adp_parse_ad_conn_file" line 14)
invoked from within
"$handler"
("uplevel" body line 2)
invoked from within
"uplevel $code"
invoked from within
"ad_try {
$handler
} ad_script_abort val {
# do nothing
}"
invoked from within
"rp_serve_concrete_file [ad_conn file]"
(procedure "::nsf::procs::rp_serve_abstract_file" line 60)
invoked from within
"rp_serve_abstract_file "$root/$extra_url""
("uplevel" body line 2)
invoked from within
> On Dhuʻl-Q. 20, 1441 AH, at 21:14, Iuri de Araujo Sampaio <[email protected]>
> wrote:
>
> Hi there,
>
> My code's intended to open a websocket connection to the echo service, wait
> 400ms to ensure that the connection is really established and send a textual
> message, which should be echoed back by the echo service.
>
> The last part will be handling/parsing that message (i.e. TXT or JSON
> message, which was echoed in that channel). Thus, every time a message comes
> through the channel a callback will be in charge to parse that message and
> store its content.
>
> However, when I run the first version of the code, and it returns an error
> related to: Error: can't set "formMap": variable is array
>
>
> /usr/local/src/ns-4.9.17/tcl8.6.8/library/http/http.tcl: return [string
> map $formMap $string]
> /usr/local/src/tcl8.6.9/library/http/http.tcl: variable formMap [array
> get map]
>
>
> The error is related to core packages, and I believe it happens to fail
> because that source is some sort of an old code. Thus, it’s not a good idea
> to fork it at all.
> How would refactor a "background websocket connection", using the new
> implementation available at:
> https://bitbucket.org/naviserver/websocket/src/master/
> <https://bitbucket.org/naviserver/websocket/src/master/> ?
>
> Here it’s the code
>
> package require websocket
> ::websocket::loglevel debug
> proc handler { sock type msg } {
> switch -glob -nocase -- $type {
> co* {
> ns_log Notice "Connected on $sock"
> puts "Connected on $sock"
>
> }
> te* {
> ns_log Notice "RECEIVED $msg"
> puts "RECEIVED: $msg"
> }
> cl* -
> dis* {
> }
> }
>
> }
> proc test { sock } {
> puts "[::websocket::conninfo $sock type] from [::websocket::conninfo
> $sock sockname] to [::websocket::conninfo $sock peername]"
>
> ::websocket::send $sock text "Testing, testing..."
> }
> set sock [::websocket::open
> wss://javascript.info/article/websocket/demo/hello
> <wss://javascript.info/article/websocket/demo/hello> handler]
> ns_log Notice "SOCKET \n $socket"
> after 400 test $sock
> vwait forever
>
>
>
>
> Documentation Reference:
> https://core.tcl-lang.org/tcllib/doc/tcllib-1-17/embedded/www/tcllib/files/modules/websocket/websocket.html#1
>
> <https://core.tcl-lang.org/tcllib/doc/tcllib-1-17/embedded/www/tcllib/files/modules/websocket/websocket.html#1>
>
>
> Best wishes,
> I
>
>
>
>
>
>
> [11/Jul/2020:20:39:38][471.7efbf37fe700][-conn:iurix:0:91-] Error: can't set
> "formMap": variable is array
> while executing
> "variable formMap [array get map]"
> (procedure "init" line 15)
> invoked from within
> "init"
> (in namespace eval "::http" script line 83)
> invoked from within
> "namespace eval http {
> # Allow resourcing to not clobber existing data
>
> variable http
> if {![info exists http]} {
> array set http {
> -ac..."
> (file "/usr/local/ns/lib/tcl8/8.6/http-2.9.0.tm" line 16)
> invoked from within
> "source -encoding utf-8 /usr/local/ns/lib/tcl8/8.6/http-2.9.0.tm"
> ("package ifneeded http 2.9.0" script)
> invoked from within
> "package require http 2.7"
> (file "/usr/local/ns/lib/tcllib1.19/websocket/websocket.tcl" line 20)
> invoked from within
> "source /usr/local/ns/lib/tcllib1.19/websocket/websocket.tcl"
> ("package ifneeded websocket 1.4.1" script)
> invoked from within
> "package require websocket"
> ("uplevel" body line 3)
> invoked from within
> "uplevel {
>
> package require websocket
> ::websocket::loglevel debug
> proc handler { sock type msg } {
> switch -glob -nocase -- $type {
> co* {
> ..."
> (procedure "code::tcl::/var/www/iurix//packages/ix-websocket/www/ws2"
> line 2)
> invoked from within
> "code::tcl::$__adp_stub"
> ("uplevel" body line 12)
> invoked from within
> "uplevel {
>
> if { [file exists $__adp_stub.tcl] } {
>
> # ensure that data source preparation procedure exists and is
> up-to-date
> ..."
> (procedure "adp_prepare" line 2)
> invoked from within
> "adp_prepare"
> invoked from within
> "template::adp_parse $themed_template {}"
> (procedure "adp_parse_ad_conn_file" line 14)
> invoked from within
> "$handler"
> ("uplevel" body line 2)
> invoked from within
> "uplevel $code"
> invoked from within
> "ad_try {
> $handler
> } ad_script_abort val {
> # do nothing
> }"
> invoked from within
> "rp_serve_concrete_file [ad_conn file]"
> (procedure "::nsf::procs::rp_serve_abstract_file" line 60)
> invoked from within
> "rp_serve_abstract_file "$root/$extra_url""
> ("uplevel" body line 2)
> invoked from within
> "uplevel $code"
> invoked from within
> "ad_try {
> rp_serve_abstract_file "$root/$extra_url"
> set ::tcl_url2file([ad_conn url]) [ad_conn file]
> se..."
> called from rp_handler
> GET http://iurix.com/websocket/ws2? <http://iurix.com/websocket/ws2?>
> referred by '' peer 192.199.241.135 user_id 0
>
> Host: iurix.com <http://iurix.com/>
> X-Real-IP: 179.199.201.237
> Connection: close
> Upgrade-Insecure-Requests: 1
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4)
> AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
> Accept:
> text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
> Accept-Language: pt-BR,pt;q=0.9,en-US;q=0.8,en;q=0.7
> Cookie: _ga=GA1.2.1048850939.1594336017;
> _gid=GA1.2.432393726.1594336018; mycrawler=-6040px%3A2521px%3Aleft;
> ad_session_id="44640008%2c0%2c0%2c1594507600%20{834%201594508800%20914BAD40D8EF86359761E4528028EE55857B5F51}"
>
> _______________________________________________
> naviserver-devel mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/naviserver-devel
_______________________________________________
naviserver-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/naviserver-devel