connecting two process through a socket

Steven Taschuk staschuk at telusplanet.net
Fri Feb 28 11:59:57 EST 2003


Quoth user at domain.invalid:
> What I am trying to do is combine two daemons. The first
> daemon logs is status in various ways: file,syslog and status
> files which take the form /path/to/status/dir/currentpid/file.
> The other daemon is a threading tcpip server which listen on
> port 3030 (configurable). The problem I have here is that I
> need to get the pid of the first daemon so that second daemon
> can feed data to clients.
  [diagram from further down in the OP]
>     ----------           ---------
>    |          |         |         |  ------->client1
>    | daemon1  |<------->| daemon2 |  ------->client2
>    |          |         |         |  ------->clientn
>     ----------           ---------
  [...]
> So, what I am considering is having the first daemon send data to
> the second through a socket.

If I understand correctly: Daemon1 sends logging information to
files, syslog, and also to daemon2.  Clients connect to daemon2 if
they want to read the log, and daemon2 sends them the logging
information as it receives it.

If this is correct, you might find it useful to have syslogd
involved: syslogd can send logging information to a socket.  Under
such a configuration, daemon1 would just log to syslog, and
syslogd would take care of forwarding the information to daemon2.

> [...] Is there a way to have the two
> daemons connected this way, and having the second daemon
> shutdown when the socket is closed? [...]

I'm not sure I understand the question.  Why not just have daemon2
read until there's no more data or a socket.error is raised, then
terminate?

Am I missing something?

> [...] And how can I make sure
> that clients do not connect to the first daemon, only the second?

You should also consider how can you make sure that clients can
connect to daemon2 only as clients, and not as if they were
daemon1.  (If they can connect the same way daemon1 does, they can
disseminate forged logging information to the other clients. 
Probably not good.)

The answers to both questions depends on the configuration.  If
the machines running daemon1 and daemon2 are trustworthy and do
not run clients, packet filtering on the IP address would do the
job.  Otherwise some authentication method is needed to assure the
daemons that they're talking to the right entity; probably best is
to re-use an existing mechanism, say, SSL.

> In other words, can I have a socket server that is connected to
> another server as a client?

Absolutely.  Every DNS server, SMTP server, NNTP server, and HTTP
proxy in the world does this, or can.

-- 
Steven Taschuk                               staschuk at telusplanet.net
"What I find most baffling about that song is that it was not a hit."
                            -- Tony Dylan Davis (CKUA)





More information about the Python-list mailing list