Linux通訊端(1)

來源:互聯網
上載者:User

Linux通訊端(1)

通訊端的特性由三個屬性確定 : 域, 類型, 協議.

1.域

AF_UNIX UNIX域協議 ( 檔案系統通訊端)

AF_INET ARPA網際網路協議 (UNIX網路通訊端)

...省略

2.類型

1) 流通訊端: SOCK_STREAM

2) 資料通訊端 : SOCK_DGRAM

3. 協議

一般由通訊端類型和通訊端域來決定, 通常不需要選擇. 將該參數設定為0表示使用預設協議.

通訊端地址.

1) AF_UNIX

struct sockaddr_un {

sa_family_t sun_family; /* AF_UNIX */

char sun_path[]; /* pathname */

};

2) AF_INET

struct sockaddr_in {

short int sin_family; /* AF_INET */

unsigned short int sin_port; /* port number */

struct in_addr sin_addr; /* Internet address */

}; 該結構定義在標頭檔 netinet/in.h 中

IP地址結構in_addr被定義為:

struct in_addr {

unsigned long int s_addr;

};

1. 命名通訊端

#include <sys/socket.h>

int bind( int socket, const struct sockaddr *address, size_t address_len);

2. 建立通訊端隊列

#include <sys/socket.h>

int listen( int socket, int backlog);

3.接受串連

#include <sys/socket.h>

int accept( int socket, struct sockaddr *address, size_t *address_len );

4.請求串連

#include <sys/socket.h>

int connect( int socket, const struct sockaddr *address, size_t address_len);

5.關閉通訊端

close();

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.