This socket class is a C++ programming interface for using sockets. The current implementation uses stream sockets of the INET type. Modification to support datagram sockets and sockets of other types is left to the reader.
Member functions:
For both client and server
- create() creates a new socket
- read() is used to read bytes from a socket
- write() is used to write bytes to a socket
- bind() gives the socket a port number. A port number is unique within one computer
- listen() makes a socket listen for incoming connection requests
- accept() acknowledges the connection request and tries to set up the connection to enable data transport. accept() uses a newly created socket for data transport. That way the listening socket can continue listening for incoming requests
- connect() sends a connection request to another socket
To enable finding a socket in the network we need a socket address. This is formed by the IP address (or host name) of the computer and a port number. A listening socket gets a port address with the bind() call. An active socket that wants to connect to a listening socket uses that socket's IP address or host name and its port number in the connect() call.
socket.h
socket.cpp