Issue
I'm working on embedded system with modem and I want to connect from modem to anything that can show data from client and optionally send some data to client.
I'm looking for a tool that would:
- open TCP socket
- print some info when client connects
- print incoming data
- send some data to client, maybe input from console? (optional)
- print some info when client disconnects
I could just take this (or another socket example) and compile it:
https://www.geeksforgeeks.org/tcp-server-client-implementation-in-c/
but maybe there is something like this or much better in Debian APT repositories?
Solution
For a simple TCP server you could use netcat
:
Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project and is the culmination of the currently splintered family of Netcat incarnations. It is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses.
It can provide bidirectional communication through TCP/UDP. There's even some HTTP server implementations using only netcat.
It'd be as easy as:
$ nc -l 0.0.0.0 9999
And voilá, you're now listening to the port 9999 in all interfaces and can connect from your device.
To test the communications you can also use netcat
. In another bash session, try this:
$ nc 127.0.0.1 9999
Easy and available on all distros :)
Answered By - Gustavo Kawamoto Answer Checked By - Marilyn (WPSolving Volunteer)