35 | | * socket() 會在 linux 上產生一個檔案名稱,通常存在 /tmp 中,檔案名稱也就是服務的辨識子埠號 (port #),負責將連接請求繞到正確的伺服器處理程序。[wiki:wade/tcp_port_list] |
| 34 | * socket() 會在 linux 上產生一個檔案名稱,通常存在 /tmp 中,檔案名稱也就是服務的辨識子埠號 (port #),負責將連接請求繞到正確的伺服器處理程序。[wiki:wade/tcp_port_list]。 |
| 35 | * 範例: |
| 36 | {{{ |
| 37 | int socket ( int domain, int type, int protocol ); |
| 38 | -- domain: |
| 39 | PF_UNIX, PF_LOCAL local connection 用在本機內資料傳輸。 |
| 40 | 資料型態:#include <sys/un.h> |
| 41 | struct sockaddr_un{ |
| 42 | sa_family_t sun_family; /*AF_UNIX*/ |
| 43 | char sun_path[]; /*pathname*/ |
| 44 | }; |
| 45 | PF_INET IPv4 Internet protocols IP 的通訊協定。 |
| 46 | 資料型態:#include <netinet/in.h> |
| 47 | struct sockaddr_in{ |
| 48 | short int sin_family; /*AF_INET*/ |
| 49 | unsigned short int sin_port; /*Port number*/ |
| 50 | struct in_addr sin_addr; /*Internet address*/ |
| 51 | }; |
| 52 | -- type: |
| 53 | SOCK_STREAM TCP 提供循序、雙向、可確保完整性的資料傳輸。 |
| 54 | SOCK_DGRAM UDP 提供不需連接,不確保完整性的資料傳輸。 |
| 55 | -- protocol: |
| 56 | 參考 /etc/protocols ,常用 0 。 |
| 57 | }}} |