Presentation is loading. Please wait.

Presentation is loading. Please wait.

SOCKET( ).

Similar presentations


Presentation on theme: "SOCKET( )."— Presentation transcript:

1 SOCKET( )

2 Socket() Bind() Listen() Read() Close() Write() Connect() Accept() client 連線建立 要求資料 回覆資料 告知傳輸結束 等待連線要求

3 Socket() #include<sys/socket.h>
Int socket( int domain, int type , int protocol); Domain:指定建立socket的定址協定 AT_INET(TCP/IP架構) Type :以值定所建立socket使用之傳輸層協定 SOCK_STREAM(TCP) SOCK_DRRAM(UDP) Protocol :通常設為 0

4 Bind() #include<sys/socket.h>
int bind ( int socketfd, const sockaddr*address , size_t addrlen) Socketfd :socket descriptor ,socket( )之回傳值 Address :網路位置結構的指標 Addrlen :sizeof (*address)

5 Connect() #include<sys/socket.h>
Int connect(int socketfd,const sockaddr *address, size_t addrlen); Socketfd :要建立連線之socket descriptor Address: 網路位置結構指標 Addrlen:sizeof(*address)

6 Listen() #include<sys/socket.h>
Int listen(int socketfd, int backlog); Socketfd: socket descriptor Backlog:最大連線數量

7 Accept() #include<sys/socket.h>
Int accept( int socketfd, struct sockaddr *cliaddr, socklen_t addrlen); Socketfd: listening socket descripion Cliaddr: 連線client 的網路位置資訊 Addrlen :sizeof(cliaddr)

8 Read() and write() #include<sys/socket.h>
Int read( int sockfd ,char *buf, int len); Socketfd:接收資料之socket description Buf :儲存讀取資料 Addrlen : sizeof(buf)

9 write() #include<sys/socket.h>
Int write( int sockfd , char *buf, int len); Socketfd : 傳送資料之socket description Buf : 儲存讀取資料 Addrlen: sizeof(buf)

10 Recv() and send() #include<sys/socket.h>
Ssize_t recv(int sockfd, void *buf, size_t nbytes, int flag); Socketfd: 接收資料之socket description Buf: 儲存讀取資料暫存區 Addrlen: sizeof(buf) Flag: 設定函數屬性

11 send() #include<sys/socket.h>
Ssize_t send(int sockfd, const void *buf, size_t nbytes , int flag); Socketfd: 接收資料之socket description Buf: 儲存讀取資料暫存區 Addrlen: sizeof(buf) Flag: 設定函數屬性

12 Close() #include<unistd.h> Int close(int socket);
Sockfd : 欲關閉之socket的socket descriptor


Download ppt "SOCKET( )."

Similar presentations


Ads by Google