coapcloud / libcoap-minimal

A minimal client and server example for libcoap
MIT License
0 stars 0 forks source link

Server working when testing from host on macOS #1

Open beriberikix opened 5 years ago

beriberikix commented 5 years ago

The main goal of this fork is to make the libcoap-minimal work in a Docker container.

Everything is building correctly and I can verify server by logging into the container and running coap-client coap://127.0.0.1/hello - it should return world. When I run coap-client on my mac, it just hangs. I can verify the the request is going through by using coap-client -v 9 and the NET I/O from docker stats.

With my limited experience in docker networking, I'm not sure what's going wrong. One theory is how CMD or or ENTRYPOINT may be used?

tiborvass commented 5 years ago

@beriberikix can you provide the exact commands to reproduce ?

beriberikix commented 5 years ago

Sure! I'm using VSC, so some of these commands are generated by the GUI.

docker build --rm -f "Dockerfile" -t coapserver:v1 .
docker run --rm -d -p 5683:5683/udp coapserver:v1
docker exec -it 4757d733c328dcb1eca1734abf4cbb6d8c20aec480f8c778561dff073091ffc6 /bin/sh -c "[ -e /bin/bash ] && /bin/bash ||

// in the container
/ # coap-client coap://127.0.0.1/hello
world

// on macOS host
coap-client -v 9 coap://127.0.0.1/hello
docker stats

If you don't want to hassle with building coap-client on your local machine, there's a simpler coap-cli written in Node.js that should be interchangeable for this test.

npm install coap-cli -g
coap get coap://127.0.0.1/hello
tiborvass commented 5 years ago

It looks like this is a Docker for Mac issue with UDP. I reproduced with a simple netcat.

tiborvass commented 5 years ago

I opened https://github.com/docker/for-mac/issues/3603

beriberikix commented 5 years ago

I replied on the Docker/for-mac ticket but netcat for UDP works just fine, so it must be something with the server.

tiborvass commented 5 years ago

Ugh, I just realized I had this tab open with the following unsent comment:

@beriberikix try changing localhost to 127.0.0.1 in https://github.com/coapcloud/libcoap-minimal/blob/master/server.cc#L26

And I just saw that you did precisely that in d85ada665cce9bff945e4cde21bf80108a71e484 Does it mean it's fixed?

beriberikix commented 5 years ago

Unfortunately not :(. It was a red herring on my local development machine. I'm hoping to hear from the libcoap maintainer over at obgm/libcoap-minimal/issues/3 to see if there's anything that might be the issue in the server implementation.

I should probably roll back that commit 🤔