erlang 如何在Cowboy中使用ws和wss进行网络聊天?

pu3pd22g  于 2022-12-08  发布在  Erlang
关注(0)|答案(1)|浏览(208)

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?

niwlg2el

niwlg2el1#

我和牛仔一起穿袜子
牛仔

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}]}]),

索基斯

var socket = new SockJS('/ws')

它在https上运行得很好

相关问题