User Datagram Protocol.ppt

  1. 1、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
User Datagram Protocol.ppt

User Datagram Protocol An initial look at using the UDP transport protocol for sending and receiving network packets The Client/Server Paradigm A great many network applications employ this asymmetrical program-design idea: The sockets API for server ‘udpserver.cpp’ and ‘udpclient.cpp’ This pair of network application-programs provides us with a simple illustration of the basic paradigm: First, launch ‘udpserver’ on station A Then launch ‘udpclient’ on station B We can watch the ethernet frames being sent and received using our ‘nicwatch’ The packet format The UDP header The IP header The Frame header Algorithm Using ‘setsockopt()’ There is a socket-option at the IP-Level which allows an application program to adjust the ‘Time-to-Live’ value assigned to any outgoing UDP packet’s IP header Demo: ‘tweakttl.cpp’ This program allows a user to specify the destination hostname, the port-number, and the desired ‘Time-to-Live’ value For example: $./tweakttl stargate 54321 5 You can watch the outgoing packet, and any ICPM reply-message, with ‘nicwatch’ * server application runs on station A time client application runs on station B request response server struct sockaddr_in saddr = {0}; int salen = sizeof( saddr ); saddr.sin_family = AF_INET; saddr.sin_port = htons( port ); saddr.sin_addr = htonl( INADDR_ANY ); sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); bind( sock, (sockaddr*)saddr, salen ); struct sockaddr_in peer = {0}; int plen = sizeof( peer ); char buf[ BUFSIZ ] = {0}; recvfrom( sock, buf, BUFSIZ, 0, (sockaddr*)peer, plen ); sendto( sock, buf, BUFSIZ, 0, (sockaddr*)peer, plen ); close( sock ); The sockets API for client client struct hostent *pp = gethostbyname( peername, NLEN ); struct sockaddr_in peer = {0}; int plen = sizeof( peer ); peer.sin_family = AF_INET; peer.sin_port = htons( port ); peer.sin_addr.s_addr = *(uint32_t*)pp-h_addr; sock = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); char msg[ MS

文档评论(0)

gshshxx + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档