aiocoap icon indicating copy to clipboard operation
aiocoap copied to clipboard

Websocket usage

Open gilloud opened this issue 4 years ago • 2 comments

Hi,

Thanks @chrysn for this incredible project and espacially for the websocket implementation. As I can see, it's the first websocket implementation of the RFC ! I'm looking for using it, and I'm currently blocked to select the websocket protocol into the server.py example. As I can see, the client example switch automatically, based on the protocol in cli : "./aiocoap-client coap+ws://localhost/time"

Will it be possible to provide an example of how to change the protocol and be able to switch to tcp, websockets, ...

my configuration:

▸python3 -m aiocoap.cli.defaults
Python version: 3.8.2 (default, Jul 16 2020, 14:00:26)
[GCC 9.3.0]
aiocoap version: 0.4b3.post0
Modules missing for subsystems:
    dtls: missing DTLSSocket
    oscore: missing cbor2, filelock
    linkheader: missing LinkHeader
    prettyprint: missing LinkHeader, cbor2, termcolor, pygments
Python platform: linux
Default server transports:  tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Selected server transports: tcpserver:tcpclient:tlsserver:tlsclient:ws:udp6
Default client transports:  tcpclient:tlsclient:ws:udp6
Selected client transports: tcpclient:tlsclient:ws:udp6
SO_REUSEPORT available (default, selected): True, True

gilloud avatar Sep 10 '20 15:09 gilloud

The server automatically starts at all supported protocols unless the default server transports are overridden. (The coaps+tcp and coaps+ws servers start only if TLS certificates are passed in).

There is a slight oddity in the coap+ws server though in that while the default port number is 80, the server (unless instructed otherwise, which is currently iffy) binds to the non-standard port 8683. The (only recently rebuilt, gotta check whether that could be automated) documentation outlines the rationale for that.

For clients, that means they have to specify the nonstandard port, eg. like this:

$ ./aiocoap-client coap+ws://localhost:8683/.well-known/core

If you are running a regular web server on the host you're running your aiocoap server on, an option to consider is to make the web server forward requests to /.well-known/coap to the other port, but I don't have documentation for that yet.

I'm leaving this issue open as a reminder to myself to cover alternative transports in the guided tour, and to reference the example web server configuration that should go with the abovementioned docs.

chrysn avatar Sep 10 '20 15:09 chrysn

Thanks a lot for this examples and explanations about the port number! The base work for me.

Regarding to your example for aiocoap-client, I have received an error from the server due to the non-installation of link_header module. ModuleNotFoundError: No module named 'link_header'

After pip3 install link_header, it's working !

Thanks

gilloud avatar Sep 11 '20 08:09 gilloud