I am trying to connect swi-prolog
with nodejs
but, without success. I have looked in the official documentation of swi-prolog
but, I see it very confusing.
I have a server in nodejs
running on port 8080. What I want is that nodejs
receive the messages sent by swi-prolog
and that swi-prolog
can receive the messages that nodejs
send you.
In nodejs
I use the module socket.io
to handle websockets
In swi-prolog
I use the websockets module that already has it by default in the official documentation. I can not understand it very well.
I hope it's not too much to ask for, an example of how to send and receive messages via websocket in swi-prolog
.
with the documented code if possible.
This is the code I have done in swi-prolog
:
:- use_module(library(http/websocket)).
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
URL = 'http://localhost:8080',
http_open_websocket(URL, WS, []),
ws_send(WS, text('hola mundo!')),
ws_receive(WS, Reply),
ws_close(WS, 1000, "Goodbye").
URL = 'http://localhost:8080',
WS = <stream>(0xe4a440,0xe4a610),
Reply = websocket{data:"hola mundo!", opcode:text}.