# Calling websocket echo server within swish -- fails to connect

**URL:** <https://swi-prolog.discourse.group/t/calling-websocket-echo-server-within-swish-fails-to-connect/1412>\
**Category:** Help!\
**Created:** [October 21, 2019, 8:28pm UTC](https://swi-prolog.discourse.group/t/calling-websocket-echo-server-within-swish-fails-to-connect/1412 "2019-10-21T20:28:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [October 21, 2019, 8:28pm UTC](https://swi-prolog.discourse.group/t/calling-websocket-echo-server-within-swish-fails-to-connect/1412/1 "2019-10-21T20:28:33Z")

</div>

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:

```prolog
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:

```prolog
:- 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).

```

---

<div class="post-metadata">

**Author:** ![grossdan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/grossdan/32/23_2.png) [@grossdan](https://swi-prolog.discourse.group/u/grossdan)\
**Post date:** [October 21, 2019, 8:47pm UTC](https://swi-prolog.discourse.group/t/calling-websocket-echo-server-within-swish-fails-to-connect/1412/2 "2019-10-21T20:47:08Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jan](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jan/32/4_2.png) [@jan](https://swi-prolog.discourse.group/u/jan)\
**Post date:** [October 23, 2019, 11:49am UTC](https://swi-prolog.discourse.group/t/calling-websocket-echo-server-within-swish-fails-to-connect/1412/3 "2019-10-23T11:49:36Z")

</div>

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.
