1 / 12

SOCKET( )

SOCKET( ). Socket(). Bind(). client. Listen(). Socket(). Accept(). 連線建立. 等待連線要求. Connect(). Read(). 要求資料. Write(). Write(). 回覆資料. Read(). Read(). 告知傳輸結束. Close(). Close(). Socket(). #include<sys/socket.h> Int socket( int domain, int type , int protocol);

laszlo
Télécharger la présentation

SOCKET( )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SOCKET( )

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

  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

More Related