babelouest / ulfius

Web Framework to build REST APIs, Webservices or any HTTP endpoint in C language. Can stream large amount of data, integrate JSON data with Jansson, and create websocket services
https://babelouest.github.io/ulfius
GNU Lesser General Public License v2.1
1.07k stars 183 forks source link

uwsc can't connect to socket while wscat can #267

Closed atodorov closed 1 year ago

atodorov commented 1 year ago

Describe the issue I have an application packaged inside a docker container which is failing to communicate to the host over Websocket (plain HTTP works). It's a JSON-RPC over HTTP + WS. This has nothing to do with uwsc, however in this setup I was using uwsc in order to debug the connection. Here's what I uncovered:

root@017e9e7a5b42:/subscan/cmd# echo '{"id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [] }' | uwsc --add-header "Content-Type: application/json"  ws://host.docker.internal:9944/
Error connecting to websocket

root@017e9e7a5b42:/subscan/cmd# 
root@017e9e7a5b42:/subscan/cmd# wscat -c ws://host.docker.internal:9944/
Connected (press CTRL+C to quit)
> {"id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [] }
< {"jsonrpc":"2.0","result":"0x41493a270d829bc1fe2636f59dd567f650c478a977544c07ca1992747b26550e","id":1}

So two different clients trying to do the same thing. Any idea why uwsc fails but wscat doesn't ?

System (please complete the following information):

Additional context Add any other context about the problem here.

babelouest commented 1 year ago

Hello,

It's hard to say without more information, but Buster's version may be outdated, you could try by installing the last release. Remove your installed packages ulfius, yder and orcania first.

Also, you can't pass your message using a pipe, it must be in the program prompt, when the connection is opened, like in wscat.

And finally, you can use the option --output-log-file=PATH to specify a log file where you might have more information.

atodorov commented 1 year ago

From the Buster .deb package:

# uwsc --add-header "Content-Type: application/json"  ws://host.docker.internal:9944
Error connecting to websocket

After installing packages from the latest release:

# uwsc -v
0.12

# dpkg -S libulfius
libulfius: /usr/lib/libulfius.so.2.7.13
libulfius: /usr/lib/libulfius.so.2.7
libulfius: /usr/lib/pkgconfig/libulfius.pc
libulfius: /usr/lib/libulfius.so

# uwsc --add-header "Content-Type: application/json"  ws://host.docker.internal:9944
Websocket connected, you can send text messages of maximum 256 characters.
To exit uwsc, type !q<enter>
> {"id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [] }
Send '{"id": 1, "jsonrpc": "2.0", "method": "chain_getBlockHash", "params": [] }'
Server message: '{"jsonrpc":"2.0","result":"0xb7714675d7f94d616fce6e3480a106c049e665b4ecd06bd6d6ed9728374eb569","id":1}'

So it looks like the stock version in Buster is old. Closing!

Update: Updated to Debian 11 Bullseye and the stock .deb package there works for me too.