Re: Make serial data available over TCP
From: Rob Mayoff (usenet_at_rob.dqd.com)
Date: 05/16/03
- Next message: Sean Burke: "Re: Make serial data available over TCP"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Unable to dlopen libjava.a: No such file or directory on AIX"
- In reply to: Robin Bowes: "Make serial data available over TCP"
- Next in thread: Sean Burke: "Re: Make serial data available over TCP"
- Reply: Sean Burke: "Re: Make serial data available over TCP"
- Reply: Robin Bowes: "Re: Make serial data available over TCP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Date: 16 May 2003 12:41:19 -0700
"Robin Bowes" <robin-news@robinbowes.com> wrote in message news:<hz1xa.119$N02.30570@newsfep1-win.server.ntli.net>...
> One way to solve this would be to write a small process that creates a fifo,
> connects to the serial port, and writes all incoming data from the serial
> port to the fifo. Another process would run under tcpsever and, every time a
> connection is made would read from the fifo and write to the network
> connection.
Your approach won't work. Each byte written to a FIFO will be delivered
to at most a single reader.
I like tcpserver, but in this case, you're probably better off not using it.
Try this instead:
Open a socket to listen for connections.
Set stdin and the listening socket to non-blocking.
Block SIGPIPE.
Loop:
Select/poll both stdin and listening socket for readability.
If listening socket is readable, accept a new connection.
If stdin is readable:
Read from it
Loop over each connection:
Write data to connection.
If write returns EPIPE, close the connection and forget it.
End loop.
End if.
End loop.
Run this program with stdin redirected from the serial port. Or, if
necessary, write a separate program that reads from the serial port and
writes to stdout, and pipe the programs together.
You also need to decide what to do if a client is too slow to keep up.
There are two trivial choices. You could set each accepted connection to
non-blocking, and just let clients miss data when they're too slow. Or
you can use exactly the algorithm above, forcing all clients to receive
data as slowly as the slowest client. The non-trivial option is to put a
dynamically-growable buffer in front of each client.
- Next message: Sean Burke: "Re: Make serial data available over TCP"
- Previous message: Jens.Toerring_at_physik.fu-berlin.de: "Re: Unable to dlopen libjava.a: No such file or directory on AIX"
- In reply to: Robin Bowes: "Make serial data available over TCP"
- Next in thread: Sean Burke: "Re: Make serial data available over TCP"
- Reply: Sean Burke: "Re: Make serial data available over TCP"
- Reply: Robin Bowes: "Re: Make serial data available over TCP"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] [ attachment ]
Relevant Pages
|