ejabberd: Why is Websocket connection not opening

2019-07-25 06:51发布

问题:

I am trying to make a websocket connection from Strophe.js to Ejabberd but ejabberd is not able to make a websocket connection.

Here is the detail:

ejabberd version: 16.02

Web socket headers

General

Request URL:ws://localhost:5280/websocket
Request Method:GET
Status Code:101 Switching Protocols

Response Headers

Connection:Upgrade
Sec-WebSocket-Accept:BHzI4XS3kPDZJhNt4BVAaGDvv8I=
Sec-Websocket-Protocol:xmpp
Upgrade:websocket

Request Headers

Accept-Encoding:gzip, deflate, sdch
Accept-Language:en-US,en;q=0.8
Cache-Control:no-cache
Connection:Upgrade
Host:localhost:5280
Origin:http://localhost
Pragma:no-cache
Sec-WebSocket-Extensions:permessage-deflate; client_max_window_bits
Sec-WebSocket-Key:eErMAKwTSckMghBGWY3KtQ==
Sec-WebSocket-Protocol:xmpp
Sec-WebSocket-Version:13
Upgrade:websocket
User-Agent:Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36

Ejabberd websocket configuration

port: 5280
module: ejabberd_http
request_handlers:
  "/websocket": ejabberd_http_ws
##  "/pub/archive": mod_http_fileserver
web_admin: true
http_bind: true
## register: true
captcha: false

ejabberd logs

2016-03-22 15:32:46.765 [info] <0.438.0>@ejabberd_listener:accept:333 (#Port<0.16207>) Accepted connection 127.0.0.1:57946 -> 127.0.0.1:5280
2016-03-22 15:32:46.766 [info] <0.1283.0>@ejabberd_http:init:158 started: {gen_tcp,#Port<0.16207>}
2016-03-22 15:32:46.777 [error] <0.1286.0>@ejabberd_hooks:run_fold1:368 {{badmatch,[<<"localhost">>]},[{mod_pubsub,serverhost,1,[{file,"src/mod_pubsub.erl"},{line,4012}]},{mod_pubsub,plugins,1,[{file,"src/mod_pubsub.erl"},{line,4038}]},{mod_pubsub,features,2,[{file,"src/mod_pubsub.erl"},{line,4116}]},{mod_pubsub,disco_local_features,5,[{file,"src/mod_pubsub.erl"},{line,512}]},{ejabberd_hooks,safe_apply,3,[{file,"src/ejabberd_hooks.erl"},{line,382}]},{ejabberd_hooks,run_fold1,4,[{file,"src/ejabberd_hooks.erl"},{line,365}]},{mod_caps,make_my_disco_hash,1,[{file,"src/mod_caps.erl"},{line,515}]},{mod_caps,caps_stream_features,2,[{file,"src/mod_caps.erl"},{line,188}]}]}
running hook: {disco_local_features,[{jid,<<>>,<<"localhost">>,<<>>,<<>>,<<"localhost">>,<<>>},{jid,<<>>,<<"localhost">>,<<>>,<<>>,<<"localhost">>,<<>>},<<>>,<<>>]}

Please help me out to understand the ejabberd log and how can I make the successful websocket connection from client to ejabberd.

回答1:

It seems this is not related to Websockets, but you seem to have hit a bug that is already fix in ejabberd repository and that will be packaged as 16.03.

If you update to latest HEAD from ejabberd repository, it should solve your pubsub crash issue.

You can find it here: https://github.com/processone/ejabberd