1 / 13

Socket 程式設計

Socket 程式設計. 蔡進義 cyt@pmlab.iecs.fcu.edu.tw. 大綱. TCP/IP 協定介紹 什麼是 Socket. TCP/IP 協定介紹. FTP, SMTP, Telnet, DNS, SNMP. What is TCP/IP Transmission Control Protocol/Internet Protocol. TCP , UDP. 應用. Application. IP , ARP. 傳輸. Transport. Ethernet, FDDI, Token Ring. 網路. Network. 資料連結.

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程式設計 蔡進義 cyt@pmlab.iecs.fcu.edu.tw

  2. 大綱 • TCP/IP協定介紹 • 什麼是Socket

  3. TCP/IP協定介紹 FTP, SMTP, Telnet, DNS, SNMP • What is TCP/IP • Transmission Control Protocol/Internet Protocol TCP, UDP 應用 Application IP, ARP 傳輸 Transport Ethernet, FDDI, Token Ring 網路 Network 資料連結 Data Link

  4. Port 0 Port 1 Port 2 Port 3 … Port 65535 Port(埠) • 每一台主機有65536個ports • port 0 ~ port 65535 • 一些保留的ports • 20, 21: FTP • 23: Telnet • 80: HTTP • 未保留 • 1024 ~ 5000

  5. socket() socket() bind() connect() listen() accept() write() read() read() write() Socket(連結導向), TCP 建立連線 Client Server

  6. Socket(非連結導向), UDP socket() socket() bind() bind() sendto() recvfrom() Client Server sendto() recvfrom()

  7. Client/Server模型 • Client端: • Client開啟一個socket並且使用一個port • Client使用connect以建立連結 • TCP要經過三向交握 • Client使用read/write system call對開啟的socket做讀寫的動作 • 關閉socket以結束連結

  8. Client/Server模型 • Server端: • Server開啟一個socket並佔用一個port • 使socket進入被動模式來等待client的連結 • Server及client利用read/write system call進行對開啟的socket做讀寫的動作 • 關閉socket以結束連結

  9. 範例程式

  10. Socket位址

  11. Socket System Call • Socket() • Socketpair() • Bind() • Connect() • Listen() • Accept() • Send() • Sendto() • Recv() • Recvfrom() • Close() • Readv() • Writev() • Getpeername() • Getsocketname()

More Related