embedded control panel - can this work?
ralda at gmx.de
Tue Jan 18 16:03:55 UTC 2011
> I know I am ignorant - what would I need in a script or a C prog to
> simply send a 1-off message to tcpsvd?
In a C prog? ... connect a socket, write a message, close socket ...
that's it, nothing special (normal TCP connection)
In a script? ... echo "Your message" | netcat OPTIONS ... (don't know
the netcat options currently, but it's not difficult). Some versions of
bash do even have the ability to send directly to TCP connections using
simple redirection (e.g. it is something like: echo "Your message."
>/dev/tcp/IP_ADDRESS/PORT, but I don't know if ash does currently
> I see that tcpsvd actually opens a 2-way conversation with the other socket
TCP connections are always bidirectional communication streams. tcpsvd
does nothing special with the established connection, it just listens
for incoming connections and hands over the socket to stdin/stdout of
the program/script it starts. Think of a minimalistic inetd (you may use
inetd instead of tcpsvd if you like or have that one already running).
> - I guess I should be using it to confirm that the requested
> action has happened...?
Checking responses is always good programing practice. It depends on
your needs, if you implement those. That way you can inform the user via
a special web page response if e.g. network configuration fails (and may
be why it fails).
In C programs of mine of that type there is a function that does connect
to a given IP-address/port, sends a single message string with write,
wait for reception of a response string with read, close the socket, and
return the response string to the caller after striping of '\n' and '\r'
(in that order).
More information about the busybox