当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

复旦大学:《计算机网络 Computer Networking》课程实验指导_因特网中继聊天(IRC)服务器_socketProgramming-Part1

资源类别:文库,文档格式:PPTX,文档页数:25,文件大小:121.69KB,团购合买
点击下载完整版文档(PPTX)

Socket Programming Part 1 ZhuZhu 07302010096@fudan.edu.cn Reference: Daniel Spangenberger 15-441 Computer Networks, Fall 2007 PPT-4 Socket Programming

Zhu Zhu 07302010096@fudan.edu.cn Reference: Daniel Spangenberger 15-441 Computer Networks, Fall 2007 PPT-4 Socket Programming

Why Do I Want Networking? Goal of Networking: Communication Share data Pass Messages Say I want to talk to a friend in Singapore How can i do this? What applications and services must I use Where can I access them? How will the data get there? Will it be reliable?

 Goal of Networking: Communication  Share data  Pass Messages  Say I want to talk to a friend in Singapore…  How can I do this?  What applications and services must I use?  Where can I access them?  How will the data get there?  Will it be reliable?

Lecture Today. o Motivations for sockets o What's in a socket? o Working with Sockets Concurrent Network Applications

Motivations for Sockets What’s in a Socket? Working with Sockets Concurrent Network Applications

Layered Commuication Application Application Application Presentation Presentation End-to-end Transparency Session Session CPI Transport UDP Transport Network P Network Network Data Link 8023 Data Link WiFi Data Link sica Physical Physical Core Network

Application Presentation Session Transport Network Data Link Physical Application Presentation Session Transport Network Data Link Physical Network Data Link Physical Core Network End-to-end Transparency Application IP IP TCP/ UDP 802.3 WiFi

What's really going on.. Lets consider project one. Client(mIRO) (IRO 128.2194242:6262 TCP 128.2237.25:6667 Which Is IP Packet IP Packet IP Packet IP Packet 1 # Which Is Ethernet Ethernet Ethe Ethe Frame #1 Frame #2 Frame Frame#4

Let’s consider project one… Client (mIRC) 128.2.194.242:6262 Server (IRC) 128.2.237.25:6667 TCP IP Packet #1 IP Packet #2 IP Packet #3 IP Packet #4 Ethernet Frame #1 Ethernet Frame #2 Ethernet Frame #3 Ethernet Frame #4 Which Is also… Which Is also…

Which is easier? An application programmer(writing an IRC server) Doesn't need to send iP packets Doesn't need to send ethernet frames Doesn't need to worry about reliability Shouldn't have to Sockets do this! TCP streams UDP packetized service(Project 2) You'll be doing this! (using sockets) To share data To pass messages

 An application programmer (writing an IRC server)  Doesn’t need to send IP packets  Doesn’t need to send Ethernet frames  Doesn’t need to worry about reliability  Shouldn’t have to!  Sockets do this!  TCP streams  UDP packetized service (Project 2)  You’ll be doing this! (using sockets)  To share data  To pass messages

What's in a Socket Some information needed Where is the remote machine? IP Address Hostname (resolved to IP) Which service do i want? Port ● After that You get a file! A plain old file As simple as other Unix I/O Don't forget to close it when you're done

 Some information needed…  Where is the remote machine?  IP Address  Hostname (resolved to IP)  Which service do I want?  Port  After that…  You get a file! A plain old file!  As simple as other Unix I/O  Don’t forget to close it when you’re done!

How do i do it? Request a socket descriptor Both the client and the server need to Bunch of kernel allocations e And the server Binds to a port I am offering a service on port x. hear me roar Listens to the socket a“Hey! Say something: Accepts the incoming connection Good, you spoke up!” ● And the client Connects “ I'm interested!

 Request a socket descriptor  Both the client and the server need to  Bunch of kernel allocations…  And the server…  Binds to a port  “I am offering a service on port x. Hear me roar”  Listens to the socket  “Hey! Say something!”  Accepts the incoming connection  “Good, you spoke up!”  And the client…  Connects  “I’m interested!

Sockets: The lifecycle Client Server socket socket o bind( listen( connect( Connection Request accept( write( read( Client/ Server Session read( write() close() EOF reado close()

Client Server socket() connect() write() read() close() socket() bind() listen() accept() write() read() close() EOF read() Connection Request Client / Server Session

Step One: Socket-time Both the client and server need to setup the socket int socket (int domain, int type, int protocol) ● Domain AF INET(IPv4, also IPv6 available) Type SOCK STREAM TCP SOCK DGRAM UDP ● Protoco 0 int sockfd socket(AF INET, SOCK STREAM, 0)i

 Both the client and server need to setup the socket  int socket(int domain, int type, int protocol)  Domain  AF_INET (IPv4, also IPv6 available)  Type  SOCK_STREAM TCP  SOCK_DGRAM UDP  Protocol  0 int sockfd = socket(AF_INET, SOCK_STREAM, 0);

点击下载完整版文档(PPTX)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
共25页,试读已结束,阅读完整版请下载
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有