int s = initport(PORT_NUMBER(XXX),SERVER,SOCK_STREAM);
int client = select_server_stream(s,&fds);
int s;
int fds;
int cc = sized_read(fd,buffer,maxsize)
int cc = sized_write(fd,buffer,size)
int fd;
char *buffer;
int maxsize;
A client uses the call:
s is the server's data socket and is used as a file descriptor in further communication. The port may be specified by name (PORT_NAME("foo")), if it is registered.
Similarly, the server uses the following call:
s is the server's connection socket. To receive data or connections, the server calls select_server_stream().
This returns a file descriptor corresponding to a client, when a client has sent a message to the server. It handles initial connections as well as client deaths. s is the server's connection socket that was returned by initport(). fds is an int used by select...() for storing a bit string corresponding to client sockets. Initialize it to 0, and don't mess with it after that.
To use the file descriptors in a stream-oriented manner, use read() and write(). To use the file descriptors in a packet-oriented manner, use sized_read() and sized_write(). The sized...() calls read and write one packet at a time, while packet boundaries are ignored in read() and write().
The arguments for sized_read() and sized_write() are very similar to read() and write(). The only difference is that in sized_read(), maxsize is the maximum size of an acceptable packet.