Some Additional network API
- sendto, send, sendmsg
- #include <sys/types.h>
- #include <sys/socket.h>
- send is for a connection, and the flags are the only difference from write
- sendto can be on any type.
- sendmsg uses a smghdr struct.
- ssize_t sendto(int s, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen);
- s is the socket
- buf is the buffer containing the data to be sent
- len is the length of the buffer
- to is the information on where to send the msg, ignored in a tcp connection.
- tolen is the length of the to field.
- Flags (an or of these)
- MSG_DONTROUTE - do not allow routing
- MSG_OOB - send data as out of bound data. Move to the front of the receive queue.
- MSG_PEEK - copy the data at the front of the queue, but do not remove it.
- MSG_DONTWAIT - if there is nothing in the queue, return EAGAIN immediately.
- return of -1 indicates an error
- Otherwise return indicates the number of characters sent.
- recvfrom, recv, recvmsg
- ssize_t recvfrom(int s, void *buf, size_t len, int flags, struct sock-
addr *from, socklen_t *fromlen);
- If from is NULL, the underlying protocol will fill in the results.
- UDP
- You only need socket, and bind for the server
- you can use sendto and recvfrom
- select
- lets you look at a set of connections, and get the one that has had a change.
- This would let you have a server, with a number of connections, and service all of them.
- I knew how this worked once