Get the App
SLTechnology News&Howtos  ›  Network Security  › 

Two-way Communication between processes-- sockpair

Shulou Source: shulou.com Published: 2022-06-01 02:56:22 10月01日 Update

Sockpair is a socket that can be used for network communication as well as local inter-process communication.

Sockpair is similar to pipes, except that pipes are used for one-way communication and can only be read on one side and written on the other. If you want to use it for two-way communication between processes, you need to pipe twice and create two pipes. Sockpair can directly realize two-way communication between processes.

1 # include 2 # include 3 # include 4 # include 5 # include 6 # include 7 int main () 8 {9 int fd [2] = {0 int sock 0}; 10 int sock = socketpair (AF_LOCAL,SOCK_STREAM,0,fd); 11 if (sock)

Tags: Communication process pipeline two-way one-way two one-way only socket network network communication local machine Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Technology Microsoft vpn Huawei