1、TCP和UDP数据包发送与接收TCP和UDP数据包发送与接收实验6 TCP和UDP数据包发送与接收 一、实验目的 TCP协议是TCP/IP协议族的核心协议之一。熟悉TCP包结构对于理解网络层次结构,以及TCP协议与IP协议的关系有着重要意义。根据TCP协议的基本原理,通过封装与发送一个标准的TCP数据包,了解TCP包结构中各字段的含义与用途,从而深入理解传输层与下面各层的关系。 二、实验要求 (1)掌握TCP/UDP报头结构、各字段含义以及校验和计算方法; (2)使用Wincap(Lipcap)构造并发送TCP,UDP数据包; (3)使用原始套接字(Raw Socket)发送自定义的TCP,U
2、DP数据包; (4)使用NDIS协议驱动发送自定义的TCP/UDP数据包。 三、实验内容 实验一SOCKET编程实验 实验内容 1、 通过调试、运行“UDPClient” 和“UDPServer”实验程序,加强对网络通讯原理的了解。(或“简单Client”和“简单Server”实验程序,下同) 2、 学习分析实验程序功能结构,了解基于SOCKET编程的网络通信软件的基本设计方法。 3、 在所提供的”UDPClient” 和“UDPServer”实验程序基础上,完善程序功能。 4、 通过实验学习和了解SOKCET通信的实现方法。 实验结果分析与总结 (1)总结运行”UDPClient” 和“UD
3、PServer”实验程序的运行情况。 UDPClient运行结 coefficient not greater than 1.3; High efficiency: control 1 hour travel time between any two points within the various groups within the area up to half an hour, 1-hour access to the airport, 45min reached the citys main traffic hub, external highway for half an hour
4、 with the main channels connecting bus 1.5 hours between any two groups of core areas; Intensive: 2030 transit share rate of around 35%, 2050 bus sharing rate of 45% per cent. 3rd chapter, Yibin city, traffic situation and General . 3.1.1 city traffic status 1, external transport passenger and cargo
5、 traffic in Yibin city, traffic at the present main railway, highway, waterway and air four modes of passenger and freight transport, thereand cultural heritage, highlighting the cultural taste and shape characteristics of the city in Yibin. According to forecasts, vision 2050 population will reach
6、2.1 million people in the center of Yibin city, urban land is around 210km2. Figure 2.6-1 2050 figure 2.7 land use planning in the Center City, Yibin city development requires the development of bus rapid transit construction and socio-economic development trends, Yibin city coordination, supporting
7、 urban space layout and infrastructure networks, transport organized, internal and external traffic hub smoothly linking, realizing sustainable development of Yibin city integrated transportation system. Concrete can be summarized as, accessible, efficient, intensive and sustainable. Accessibility:
8、Central built-up area road network density of about 7.0km/km2; bus line density of 3-4 km/km2, bus transfer UDPServer运行结果 (2)设计交互程序的运行结果如下: coefficient not greater than 1.3; High efficiency: control 1 hour travel time between any two points within the various groups within the area up to half an hou
9、r, 1-hour access to the airport, 45min reached the citys main traffic hub, external highway for half an hour with the main channels connecting bus 1.5 hours between any two groups of core areas; Intensive: 2030 transit share rate of around 35%, 2050 bus sharing rate of 45% per cent. 3rd chapter, Yib
10、in city, traffic situation and General . 3.1.1 city traffic status 1, external transport passenger and cargo traffic in Yibin city, traffic at the present main railway, highway, waterway and air four modes of passenger and freight transport, thereand cultural heritage, highlighting the cultural tast
11、e and shape characteristics of the city in Yibin. According to forecasts, vision 2050 population will reach 2.1 million people in the center of Yibin city, urban land is around 210km2. Figure 2.6-1 2050 figure 2.7 land use planning in the Center City, Yibin city development requires the development
12、of bus rapid transit construction and socio-economic development trends, Yibin city coordination, supporting urban space layout and infrastructure networks, transport organized, internal and external traffic hub smoothly linking, realizing sustainable development of Yibin city integrated transportat
13、ion system. Concrete can be summarized as, accessible, efficient, intensive and sustainable. Accessibility: Central built-up area road network density of about 7.0km/km2; bus line density of 3-4 km/km2, bus transfer (3)总结程序设计的情况,列出所设计或修改部分的源代码清单。附上程序源代码。 Client端修改的代码如下: /(3)开始接收或发送过程 printf(n- waiti
14、ng for message from Seaver -n); /进入一个循环 while (1) /输入并发送信息给服务器 buffer0=0; /先清空发送缓冲区 printf(n Input datagram send info ( quit 退出 ): ); /输入发送字符串 scanf(%s,buffer); sendto(socketid,buffer,sizeof buffer,0,(struct sockaddr*)&server,server_len); /发送信息 /控制循环退出 if(strcmp(buffer,quit) = 0) /输入为quit则结束 printf(
15、n send info quit); return 0; /接收服务器返回信息 buffer0=0; /先清空接收缓冲区if(recvfrom(socketid,buffer,sizeof buffer,0,(struct sockaddr*)&server,&server_len)!=SOCKET_ERROR) /接收返回信息 coefficient not greater than 1.3; High efficiency: control 1 hour travel time between any two points within the various groups within
16、the area up to half an hour, 1-hour access to the airport, 45min reached the citys main traffic hub, external highway for half an hour with the main channels connecting bus 1.5 hours between any two groups of core areas; Intensive: 2030 transit share rate of around 35%, 2050 bus sharing rate of 45%
17、per cent. 3rd chapter, Yibin city, traffic situation and General . 3.1.1 city traffic status 1, external transport passenger and cargo traffic in Yibin city, traffic at the present main railway, highway, waterway and air four modes of passenger and freight transport, thereand cultural heritage, high
18、lighting the cultural taste and shape characteristics of the city in Yibin. According to forecasts, vision 2050 population will reach 2.1 million people in the center of Yibin city, urban land is around 210km2. Figure 2.6-1 2050 figure 2.7 land use planning in the Center City, Yibin city development
19、 requires the development of bus rapid transit construction and socio-economic development trends, Yibin city coordination, supporting urban space layout and infrastructure networks, transport organized, internal and external traffic hub smoothly linking, realizing sustainable development of Yibin c
20、ity integrated transportation system. Concrete can be summarized as, accessible, efficient, intensive and sustainable. Accessibility: Central built-up area road network density of about 7.0km/km2; bus line density of 3-4 km/km2, bus transfer printf(Received datagram from -%sn,buffer); closesocket(so
21、cketid); /关闭SOCKET连接 WSACleanup(); /退出使用wsock32.dll动态链接库 return 0; Seaver端修改的代码如下: printf(n- waiting for message from client -n); /进入一个循环 while (1) buffer0=0; if(recvfrom(socketid,buffer,sizeofbuffer,0,(struct sockaddr*)&client,&client_len)!=SOCKET_ERROR) printf(Received datagram from -%sn,buffer);
22、/给cilent发信息 / char ack100 = recv ok!; / sendto(socketid,ack,sizeof ack,0,(struct sockaddr*)&client,client_len); buffer0=0; printf(n Input datagram send info ( quit 退出 ): ); /输入发送字符串 scanf(%s,buffer); sendto(socketid,buffer,sizeof buffer,0,(struct sockaddr*)&client,client_len); /发 if(strcmp(buffer,qu
23、it) = 0) /输入为quit则结束 printf(n send info quit); return 0; /Sleep(500); closesocket(socketid); WSACleanup(); return 0; 总结: coefficient not greater than 1.3; High efficiency: control 1 hour travel time between any two points within the various groups within the area up to half an hour, 1-hour access to
24、 the airport, 45min reached the citys main traffic hub, external highway for half an hour with the main channels connecting bus 1.5 hours between any two groups of core areas; Intensive: 2030 transit share rate of around 35%, 2050 bus sharing rate of 45% per cent. 3rd chapter, Yibin city, traffic si
25、tuation and General . 3.1.1 city traffic status 1, external transport passenger and cargo traffic in Yibin city, traffic at the present main railway, highway, waterway and air four modes of passenger and freight transport, thereand cultural heritage, highlighting the cultural taste and shape charact
26、eristics of the city in Yibin. According to forecasts, vision 2050 population will reach 2.1 million people in the center of Yibin city, urban land is around 210km2. Figure 2.6-1 2050 figure 2.7 land use planning in the Center City, Yibin city development requires the development of bus rapid transi
27、t construction and socio-economic development trends, Yibin city coordination, supporting urban space layout and infrastructure networks, transport organized, internal and external traffic hub smoothly linking, realizing sustainable development of Yibin city integrated transportation system. Concret
28、e can be summarized as, accessible, efficient, intensive and sustainable. Accessibility: Central built-up area road network density of about 7.0km/km2; bus line density of 3-4 km/km2, bus transfer 在Client端接收返回信息发送信息和Seaver接收返回信息发送信息前都要进行清空接收缓冲区。 (1)掌握TCP/UDP报头结构、各字段含义以及校验和计算方法; (a)TCP报头结构 TCP头部 数据(d
29、ata) 各字段含义: , 源端口(Source Port)和目的端口(Destination Port):分别代表本次TCP通信发起主机和目的主机所使用的端口号; , 序列号(Sequence Number):该字段用来标识TCP源端设备向目的端设备发送的字节流,它表示在这个报文段中的第几个数据字节。序列号是一个32位的数。 , 确认号(Acknowledge Number):TCP使用32位的确认号字段标识期望收到的下一个段的第一个字节,并声明此前的所有数据已经正确无误地收到,因此,确认号应该是上次已成功收到的数据字节序列号加1。收到确认号的源计算机会知道特定的段已经被收到。确认号的字段只
30、在ACK标志被设置时才有效。 , 数据偏移(Data Offset):这个4位字段包括TCP头大小。由于首部可能含有选项内容,因此TCP首部的长度是不确定的。首部长度的单位是32比特或4个八位组。首部长度实际上也指示了数据区在报文段中的起始偏移值。 , 保留(Reserved):6位置0的字段。为将来定义新的用途保留。、 , 控制位(Control Bits):共6位,每一位标志可以打开一个控制功能。 URG(Urgent Pointer Field Significant,紧急指针字段标志):表示TCP包的紧急指针字段有效,用来保证TCP连接不被中断,并且督促中间齐备尽快处理这些数据。 AC
31、K(Acknowledgement field significant,确认字段标志): 取1时表示应答字段有效,也即TCP应答号将包含在TCP段中,为0则反之。 PSH(Push Function,推功能):这个标志表示Push操作。所谓Push操作就是指在数据包到达接收端以后,立即送给应用程序,而不是在缓冲区中排队。 RST(Reset the connection,重置连接):这个标志表示感谢连接复位请求,用来复位那些产生错误的连接,也被用来拒绝错误和非法的数据包。 SYN(Synchronize sequence numbers,同步序列号):表示同步序号,用来coefficient not greater than 1.3; High efficiency: control 1 hour travel time between any two points within the various groups within the area up to half an hour, 1-hour access to the airport, 45min reached the citys main traffic hub, external highway for half an hour with the main channels conn
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1