A socket behaves similar to a file (can read/write) once connected. A client connects to a server (usually TCP or UDP)
#include <sys/socket.h>
...
int sockfd = socket(AF_INET6, SOCK_STREAM, 0);
...From there, server and client start to differ.
Sockets-server
Server binds to port, listens on the socket, and accepts each client connection.
bind(sockfd, &srv_struct, len)
listen(sockfd, backlog)
newsockfd = accept(sockfd, &cl_struct, len);Now can read() and write() on newsockfd and close() later.
Sockets-client
Client connects to IP/port, and then read() and write() on socket.
connect(sockfd, &addr_struct, len)
write(sockfd, buffer, len)
...
close(sockfd)Same as server regarding read/write/close.