Specifications
if they are called the thread will stop and will only continue once they are complete. The
second way is to create what the Nut OS calls a SoStream (Socket Stream) which is a
type of Nut Device (as described in section 5.2 of this Chapter). This creates a
programming model similar to what is found in UNIX. In UNIX each device is
considered a file and you simply read and write to the file and the operating system will
handle the communication to the device. So by creating a SoStream from a TCP socket,
the Nut OS creates threads to handle the TCP receives and sends.
To use the device, the user simply writes or reads to the SoStream which puts or takes
the data in or out of a buffer which the Nut OS then uses for the underlying TCP
functions. To create this SoStream a socket is created as normal and then a TCP
connection is established between the connecting devices. Then a Nut Device is created
(which is basically a file handler with standard inputs and outputs) of type SoStream
and then was bound to the socket that was created.
When deciding between using the SoStream or handling the packets with sends and
receives it was decided to use the SoStream method, because all the examples provided
in the Nut OS used this method and it seemed much more convenient. When reading
and writing to the SoStream the function calls are no longer blocking, the Nut OS can
keep receiving TCP data into the buffer until it becomes full and then waits for it to start
to empty by reading from the SoStream.
The first implementation using the SoStream was a simple server–client program. The
Nut OS received all the TCP messages sent from the client program on the PC and put
them into a buffer. To get these messages the program simply read from the SoStream
device a set number of bytes (or less, but not greater) or a line at a time, and then sent
the data to hyper terminal via the serial port. The results from this were that the system
worked as planned; a string was sent through the TCP connection and this appeared on
HyperTerminal.
26










