Calling websocket echo server within swish -- fails to connect

Hi,

I managed to get several http calls to work within swish sandbox environment [1], but am not able to get the example from the documentation working – i tried two echo severs – which work when accessed via the browser demo they provide, but not via the code below.

http_open_websocket fails.

Any thoughts why this is the case, would be great:

URL = 'ws://demos.kaazing.com/echo',
   http:http_open_websocket(URL, WS, []),
   http:ws_send(WS, text('Hello World!')),
   http:ws_receive(WS, Reply),
   http:ws_close(WS, 1000, "Goodbye").

thank you,

Dan

p.s. i got websocket calls permitted in the sandbox via the following additions when loading custom code into swish:

:- multifile http:http_open_websocket/3.
:- multifile http:ws_send/2.
:- multifile http:ws_receive/2.
:- multifile http:ws_close/3.

sandbox:safe_primitive(http:http_open_websocket/3).
sandbox:safe_primitive(http:ws_send/2).
sandbox:safe_primitive(http:ws_receive/2).
sandbox:safe_primitive(http:ws_close/3).

Perhaps, i have the module qualifiers all wrong:

:- use_module(library(http/websocket)).

How does one qualify a predicate in the http/websocket library …

http:ws_open … is probably incorrect.

The idea of calling Module:Goal is 99% of the cases wrong. You defined new empty predicates as safe and call them. That fails. But, you do not want the websocket predicates to be safe. They can easily be used to exhaust file handles and blow up the server. You may want to define a higher level primitive that uses a websocket in a safe manner and define that as safe. You typically do that using an additional module in config-enabled.