Review Unix Sockets
High level calls (putchar getc etc) need a FILE*, read/write are low level and need a file descriptor
File pointers are different from a file descriptor.
Sockets which can communicate over networks. Does not use file names instead...
instead use : IPaddress Port Number
Interesting way in which an ipaddress is made eg 220.127.116.11 =
1 * 256^3 + 2 * 256^2 + 3 *256 + 4
Network Byte Order
- a standard order in which bytes are put onto the network. May or maynot be the same as your machine order (big-endian, little-endian). There are conversion functions to convert from host byte order to network byte order
- htonl : host to network long
convert ascii ipaddress to IP address in network byte order
- inet_pton("127.0.0.1") (also inet_addr or inet_aton)
inet_pton( AF_INET, "127.0.0.1", &address.sin_addr);
x = gethostbyname("zenit.senecac.on.ca");
getaddrinfo("zenit.senecac.on.ca", NULL, NULL, &addrinfo_var);
use setsockopt to set the SO_REUSEADDR option so that you can reuse a socket right away after closing.
use select to wait for activity on multiple file descriptors
select simply checks to see if a read(or whatever) will be non-blocking
Manipulate File Descriptor sets via
FD_ZERO - initialize a set (an fd_set structure)
FD_SET - put a file descriptor into the set
FD_CLR - remove an fd from the set
FD_ISSET - check to see if a filedescriptor is now unblocking