Socket parsing and example code of linux IPC
Socket communication under Linux is a kind of file-based IPC communication, which can also be IPC communication based on other devices. It can realize the communication between different processes in this machine, and it can also realize the communication between different hosts.
Steps to create a socket
Server side
1. Create a socket through the socket () function
two。 Bind socket to the device address through the bind function
3. Listens to the specified socket through listen
4.
Client
1. Create a socket through the socket () function
two。 Connect to the server through connect
After the above steps, the server and the client have established a link and can send / receive data through write/read or sendto/recvfrom.
1. Server side
/ / s_unix.c#include # define UNIX_DOMAIN "/ tmp/UNIX.domain" int main (void) {socklen_t clt_addr_len; int listen_fd; int com_fd; int ret; int i; static char recv_buf [1024]; int len; struct sockaddr_un clt_addr; struct sockaddr_un srv_addr; listen_fd=socket (PF_UNIX,SOCK_STREAM,0); if (listen_fd)