Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Socket parsing and example code of linux IPC

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

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)

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report