# Problem with exe and websocket at win11

**URL:** <https://swi-prolog.discourse.group/t/problem-with-exe-and-websocket-at-win11/7244>\
**Category:** Help!\
**Created:** [February 15, 2024, 4:02pm UTC](https://swi-prolog.discourse.group/t/problem-with-exe-and-websocket-at-win11/7244 "2024-02-15T16:02:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexisJQ](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@alexisJQ](https://swi-prolog.discourse.group/u/alexisJQ)\
**Post date:** [February 15, 2024, 4:02pm UTC](https://swi-prolog.discourse.group/t/problem-with-exe-and-websocket-at-win11/7244/1 "2024-02-15T16:02:12Z")

</div>

I’m using: SWI-Prolog version 9.1.22

So I’m attempting to build a exe that can run a web server with websocket. I’m compiling with this line in the command promp:

```prolog
swipl --stand_alone=true -o example -g main -c load.pl

```

this is an example of the files

**load.pl**

```prolog
:-[
    websocket
].

main:- 
    server.

```

**websocket.pl**

```prolog
:- use_module(library(http/thread_httpd)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(http/http_json)).
:- use_module(library(http/http_parameters)).
:- use_module(library(http/websocket)).
:- use_module(library(http/http_error)).

% Star the server at port 9000
server :-
    http_server(http_dispatch, [port(9000)]).

% Stop the server at Port 9000
stop:-
    http_stop_server(9000, []).
        
% Paths
:- http_handler(root(time),
    http_upgrade_to_websocket(time_handler, []),
    [spawn([])]).

time_handler(WebSocket) :-
    ws_receive(WebSocket, Message, []), % This waits until a message is received.
    (
        Message.opcode == "close"
    ->
        true
    ;
        time_response(Response_dict),
        ws_send(WebSocket, json(Response_dict)),
        time_handler(WebSocket)
    ).

time_response(Response_dict) :-
    get_time(Time),
    format_time(string(Message), '%c', Time),
    dict_create(Data, _, [message-Message]),
    dict_create(Response_dict, _, [data-Data,format-json,opcode-text]).

```

the exe ends its execution immediately after starting from powershell and I have not been able to maintain the web service.

---

<div class="post-metadata">

**Author:** ![jamesnvc](https://yyz2.discourse-cdn.com/free1/user_avatar/swi-prolog.discourse.group/jamesnvc/32/14_2.png) [@jamesnvc](https://swi-prolog.discourse.group/u/jamesnvc)\
**Post date:** [February 16, 2024, 7:52pm UTC](https://swi-prolog.discourse.group/t/problem-with-exe-and-websocket-at-win11/7244/2 "2024-02-16T19:52:58Z")

</div>

http\_server/2 doesn’t block, so the `server/0` starts the server but then immediately finishes. For my servers, I put ` thread_get_message(_)` as the last clause in my “main” predicate (so, `server :- http_server(http_dispatch, [port(9000)]), thread_get_message(_).`)
