문제

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