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?

有帮助吗?

解决方案

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top