Question

I am building a web chat over WebSockets using Cowboy and gproc.

Now, I would like to know if you could address me some projects or resources or snippet of code in order to migrate from simple websocket (ws) to web socket secure connection (wss).

Is there any way I can modify the cowboy example about WebSockets to make a chat application?

Était-ce utile?

La solution

I use sockjs with cowboy

Cowboy

SockjsState = sockjs_handler:init_state(<<"/ws">>, fun my_sockjs_handler:hook/3, state, []),

Dispatch = cowboy_router:compile([
{'_', [     
        {<<"/ws/[...]">>,sockjs_cowboy_handler, SockjsState}
    ,{'_', my_handler, []}
    ]}
]),
{ok, _} = cowboy:start_https(https, 100, [
    {port, 443},
    {cacertfile, "priv/ssl/my_cacertfile.crt"},
    {certfile, "priv/ssl/my_certfile.crt"},
    {keyfile, "priv/ssl/my_key_file.key"}
], [{env, [{dispatch, Dispath}]}]),

Sockjs

var socket = new SockJS('/ws')

And it works pretty fine on https

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top