Socket Overview
- This is chapter 56.
- Sorry people in data comm
- Sockets are bi-directional communications mechanisms.
- The communicating processes do not need to be related in any way.
- This means that there is more work in setting them up however.
-
fd = socket(domain, type, protocol);
- There are three basic types we will concentrate on.
- These are called communications domains.
- AF_UNIX: communication between processes on the same host.
- This is completely within the kernel.
- Addresses are the names.
- Address structure
sockaddr_um
- AF_INET: communications between processes on potentially different hosts, IPV4
- AF_INET6: IPV6
- This is kernel, device drivers, ...
- Address structure
- IPV4: 32 bit address and 16 bit port
-
sockaddr_in
- IPV6: 128 bit address and 16 bit port
-
sockaddr_in6
- He points out that AF stands for Address Family, apparently there are equivalent PF_ which stands for Protocol Family, but this has been abandon.
- But do a quick
man 2 socket
.
- Each of these can have one of two types we will look at
- Datagram (UDP or User Datagram Protocol)
- This is a non-reliable service
- ie the data may or may not arrive. The protocol does not take care of failed delivery.
- And may not arrive in order
- And may have duplicate deliveries.
- It does not assume a connection, ie the messages are independent.
- Stream Socket (TCP transmission Control Protocol)
- Connection oriented.
- Reliable, in order, unique delivery.
- It is just a stream, no "boundaries" between messages.
- These are not the only types, Agana
man 2 socket
- Generic Steps
- Build the socket with
socket
- Bind the socket to an address with
bind
- Wait for a connection to occur with
listen
- Form the connection with
connect
- read/write
- Close the connection with
close