Erlang and websockets

Some time ago I found an example of Joe Armstrong on Erlang and websocket, but I could not get it to work.

I fixed the error and a couple of warnings in Erlang code, but with Apache I could not get a good result.

Can someone give me some tips with a very simple example? Do I need to host a webpage with JavaScript inside the Apache directory, as for regular PHP files?

+3
source share
3 answers

The websocket Joe example is deprecated and uses an outdated version of the protocol. Modern browsers use a newer version (draft-00)

To date, a good erlang implementation is available due to misuse. Tested and compatible with current browsers:

https://github.com/ostinelli/misultin/blob/master/src/misultin_websocket.erl

+8

Yaws - websocket. ws. Erlang (, ):

https://github.com/schemeway/erlang-tools

+8

SockJS-Erlang, . , - . Cowboy ( ) , , . escript HTML .

:

start_link(_) ->
    application:start(sockjs),
    application:start(cowboy),

    % generate a SockJS handler
    SockjsState = sockjs_handler:init_state(
                    <<"/browser_socket">>, fun handle_client/3, state, []),

    % build the dispatch routes for Cowboy integrating the SockJS handler
    Routes = [{'_',  [{[<<"echo">>, '...'],
                       sockjs_cowboy_handler, SockjsState}]}],

    % start the cowboy server
    cowboy:start_listener(http, 100,
                          cowboy_tcp_transport, [{port,     8081}],
                          cowboy_http_protocol, [{dispatch, Routes}]),

% called when a new client connects
handle_client(Conn, init, state) -> {ok, state};

% called when data is received 
handle_client(Conn, {recv, Data}, state) ->
  % reply to client
  Conn:send(Data);

% called when connection is closed
handle_client(_Conn, closed, state) -> {ok, state}.

Apache - HAProxy WebSocket Apache Javascript PHP.

+3
source

Source: https://habr.com/ru/post/1776224/


All Articles