TCP is everyhere, so everyone should rest sometimes 😎
I made simple server which listen to datagrams and do actions with file system by 'fs' module.
This example is a small
antipattern. We shouldn't send a datagram with commands for file system manage (but it depends ...). If we send command for delete file, but file not exist, client should get a response with error, but this is not TCP
So in this kind of problem client/user cannot get information about transaction.
I created also UDP client
with Node for show faster way to see result.
For both app I use 'dgram' and 'fs' module in server part.
Server for fs management should get a special data buffer. In this kind I use a JSON.
- Create file
{
"action": "CREATE_FILE",
"fileName": "test.txt",
}
- Update file
{
"action": "WRITE_INTO_FILE",
"fileName": "test.txt",
"content": "ala ma kota"
}
- Delete file
{
"action": "DELETE_FILE",
"fileName": "test.txt",
}
Go to node-udp-communication/udp-server and exc commands:
npm i
npm start
- Create file
echo "{\"action\": \"CREATE_FILE\", \"fileName\": \"test.txt\"}" | nc -w1 -u 127.0.0.1 8080
- Update file
echo "{\"action\": \"WRITE_INTO_FILE\", \"fileName\": \"test.txt\", \"content\": \"ala ma kota\"}" | nc -w1 -u 127.0.0.1 8080
- Delete file
echo "{\"action\": \"DELETE_FILE\", \"fileName\": \"test.txt\"}" | nc -w1 -u 127.0.0.1 8080
Go to node-udp-communication/udp-client and exc commands:
npm i
npm start
(App send DETELE command after 10 sec)
- Node.js >= 10.0
- npm >= 6.0