I'm starting using docker. I'm creating a COAP application with a client and a server. In this application, a client sends a simple request and the server has to response to it. I built my image that runs my code in node.js. Then I used a docker-compose.yml file that I will show you in the code section. However, it seems like the server doesn't respond to the client request.
I tried to see if the IP address were well assigned, and everything seems ok. I also tried to use Wireshark on docker0 and I can see the coap packets going from the client to the server, but I don't have an answer. Here is the docker-compose.yml
services:
Server_Coap:
build: './Server_Coap'
image: 'user/mynode:latest'
container_name: server
ports:
- "8081:5683"
networks:
rete:
ipv4_address: 172.19.0.3
networks:
rete:
ipam:
driver: default
config:
- subnet: 172.19.0.0/24
Here is the client code:
const coap = require('coap'),
req = coap.request('coap://172.19.0.3')
console.log("Client Request...")
req.on('response' , function(res){
res.pipe(process.stdout)
})
req.end()
Here is the server code:
var coap = require('coap')
,server = coap.createServer()
server.on('request' , function(req, res){
console.log("New request")
res.end('Hello ' + req.url + '\n')
})
// the default CoAP port is 5683
server.listen(function() {
console.log("Server started")
})
Here is my Dockerfile for the server:
FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5683
CMD ["node" , "server.js"]
Here is my Dockerfile for the client:
FROM node:latest
WORKDIR /usr/src/app
COPY package*.json ./
RUN npm install
COPY . .
EXPOSE 5683
CMD ["node" , "client.js"]
I would like to have an answer from the server. This is the kind of error that I get: │ Error: No reply in 247s │ at Timeout._onTimeout (/usr/src/app/node_modules/coap/lib/retry_send.js:74:16) │ at listOnTimeout (internal/timers.js:531:17) │ at processTimers (internal/timers.js:475:7) │ Emitted 'error' event on OutgoingMessage instance at: │ at RetrySend.emit (events.js:209:13) │ at Timeout._onTimeout (/usr/src/app/node_modules/coap/lib/retry_send.js:77:12) │ at listOnTimeout (internal/timers.js:531:17) │ at processTimers (internal/timers.js:475:7) { │ retransmitTimeout: 247
You have to add your client docker to the network. IE:
services:
Server_Coap:
build: './Server_Coap'
image: 'user/mynode:latest'
container_name: server
ports:
- "8081:5683"
networks:
rete:
ipv4_address: 172.19.0.3
Client_Coap:
build: './Client_Coap'
image: 'user/mynode:latest'
container_name: client
networks:
rete
networks:
rete:
ipam:
driver: default
config:
- subnet: 172.19.0.0/24