网络编程技术实验指导书.doc_第1页
网络编程技术实验指导书.doc_第2页
网络编程技术实验指导书.doc_第3页
网络编程技术实验指导书.doc_第4页
网络编程技术实验指导书.doc_第5页
已阅读5页,还剩6页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

网络编程技术实验指导书董黎刚信息与电子工程学院浙江工商大学2006/10/3 14:29:00 Content1. Operation of Linux (操作性)11.1 Purpose11.2 Content11.3 Hints22. C Programming Practice(设计性)32.1 Purpose32.2 Content32.3 Grading33. Simple Socket Programming(验证性)43.1 Purpose43.2 Content43.3 Hints44. Concurrency Socket Programming(验证性)54.1 Purpose54.2 Content54.3 Hints55. Windows Socket Programming(验证性)65.1 Purpose65.2 Content65.3 Hints66. Advanced Socket Programming (设计性)76.1 Purpose76.2 Content76.3 Grading8Experiments of Network Programming Last updated: 2020/1/231. Operation of Linux (操作性)Name: No.: Class: Grading:1.1 PurposeReview the operation of Linux, in particular shell commands (bash).1.2 ContentEach student is required to finish all of the following tasks. Part I Programming 1) Use “vi” to construct a program “helloworld.c” that can print“hello world”. Compile and run it. (hint: gcc helloworld.c, ./a.out)Part II File/Directory2) Make a new sub-directory in current directory, then move “helloworld.c” into this new sub-directory. (hint: mkdir source, mv old_file new_file)3) Change the access permissions of “helloworld.c” to -rw-r-xrw-. (hint:chmod 656 helloworld.c)4) Find a file named “emacs” in hard disk. (hint: find / -name emacs)5) Make a hard link, which is called “helloworld1.c”, of “helloworld.c”. (hint: ln old_file new_file); 6) Make a symbolic link, which is called “helloworld2.c”, of “helloworld1.c”. Then remove helloworld1.c. (hint: ln s old_file new_file) Check the output of “ls l” to compare the hard link and soft link.7) Make a copy of “helloworld.c”. The new file is “helloworld3.c”. (hint: cp source_file destination_file) 8) Archive and compress all the files inside a sub-directory. (hint: tar cvf new_file.tar *, gzip old_file)Part III Text9) Show the first 10 line of helloworld.c in reverse order. (hint: head helloworld.c | sort -r)10) Print the number of bytes, words, and lines of helloworld.c to a file called “info.txt”. (hint: wc helloworld.c info.txt)11) Merge helloworld.c and info.txt to a new file “helloworld.txt”. (hint: paste helloworld.c info.txt helloworld.txt)12) Print column 3-5 of “helloworld.c”. (hint: cut c3-5 helloworld.c)13) Remove “/home/your_name/source”. (hint: rmdir, rm)Part IV Process14) compare the difference among “ps”, “ps f”, and “ps ef”. 15) execute “top” to show the most active processes.Part V I/O Devices 16) Find the free space size in hard disks and usage size of /usr/src. (hint: du, df)Part VI Networking17) Find the IP address of the local host. (hint: ifconfig)18) Change the IP address of the localhost. (hint: ifconfig eth0 up Or change /etc/sysconfig/network-scripts/ifcfg-eth0)Part VII System Management19) Find the version of Linux kernel and host name in the local host. (hint: uname a)20) Set a regular variable called “var1” and an environment variable “var2”. You can assigned any value. (hint: var1=10, export var2=3, 分别用set, env来查看)21) Find the memory and cpu usage information of this local host. (hint: cat /proc/cpuinfo, cat /proc/meminfo) 22) Find the .h file containing the definition of struct sockaddr_in in /usr/src/. (hint: grep r “struct sockaddr_in ” /usr/src/* )1.3 Hints1) 先理解命令的含义,再运行试验。如果你想了解是否有完成某项工作的命令,可以使用“apropos 关键词”;如果你想了解某个命令的细节(比如选项),可以使用“man ls”, “ls help” (以ls为例)。如果你想知道某个命令的文件在哪个目录里,可以使用“whereis ls”, “which ls” (以ls为例)。2) 命令执行完,要检查一下是否执行正确,比如用“ls l”检查是否产生了新的文件3)命令执行失败的常见错误有:a) 名字敲错;b) 命令和选项或执行对象之间没有空格;c)文件确实不在你所预想的那个目录里,这可以用“ls l”来检查;d)文件不在缺省路径里,你需要指定文件的路径。4) 用Ctrl-C强行退出正在运行的命令2. C Programming Practice(设计性)Name: No.: Class: Grading:2.1 PurposeReview the knowledge of C programming, in particular operation of structure, pointer, memory, file, etc. It is necessary before learning network programming.2.2 ContentEach student is required to construct a small information management program for managing student records (e.g, No., name, age, scores, hometown) with the following constraint.1) Use a binary file (NOT a text file) to store student records. 2) You can dynamically edit (e.g., add, remove, and show) student records. 3) You must use linked list(链表), pointer(指针), files(文件), structure(结构), dynamic allocation of space(动态分配空间).2.3 GradingContentDetailScore1.Function of programs(30)(1)记录用结构表示,至少包含字符串(如名字)和整型(如年龄)(5)(2)用链表来动态保存记录,并能以命令行或者菜单形式增加(5)、删除(5)和查询(5)内容。如果用数组最多得5分(3)用二进制文件永久保存记录,并能在程序开始运行时读取文件内容(5),在程序运行结束前保存到文件(5)2.Quality of programs(30%)(1)用大括号和缩进来清楚地显示程序结构。(提示:按一次tab键产生一个缩进)(5)(2)各函数有功能说明和参数说明(5)(3)每个源程序文件都有说明(比如本程序功能,作者,包含哪些函数)(5)(4)每个函数长度不超过100行(5)(5)函数、变量取名前后一致并容易理解(5)(6)对不容易理解的常量、变量和语句有注释(比如全局常量、变量、if语句)(5)3.Report(30%),which should be attached to this page(1)用流程图或其他有效方法描述一个主要算法(15)(2)有经验总结(15)4Debug(10%)(1)会单步运行到任何一个语句(5)(2)单步运行时能查看变量值(5)3. Simple Socket Programming(验证性)Name: No.: Class: Grading:3.1 PurposeLearn the TCP&UDP socket programming of client and server programs.3.2 Content1) Download the source code provided by the textbook using ftp2) Uncompress the source code using “zcat v3.linux.dist.tar.Z | tar xvf ”3) Compile and run the following programs in v3.Linux/examples: connectsock.c, connectTCP.c, connectUDP.c, errexit.c, passivesock.c, passiveTCP.c, passiveUDP.c, TCPdaytime.c, TCPdaytimed.c, TCPecho.c, UDPecho.c, UDPtime.c, UDPtimed.cUsing these programs, you can realize the communication between two computers for obtaining daytime and time.4) Write a server program for providing echo service. Test it using TCPecho.c3.3 Hints1) 先找到包含主函数main()的文件进行编译和连接,如果发现某些被调用函数没有找到,再把包含这些被调用函数的文件一起编译。2) 多个文件一起编译的办法有三个:一是gcc file1.c file2.c , 二是把包含被调用函数的文件用#include “file1.c”的方式包含在主函数文件中,三是建立一个工程,和VC+类似。3) 首先,通过浏览、编译、连接和运行别人的程序来学习编程;其次,尝试局部修改别人的程序来理解程序中每一个细节的含义;最后,编写自己的程序,其中可以使用别人的程序(段)。 4) errno is defined in “errno.h”4. Concurrency Socket Programming(验证性)Name: No.: Class: Grading:4.1 PurposeLearn the socket programming of using multiple-process, multiple-thread, asynchronous I/O programming.4.2 Content1) Compile and run the following programs in v3.Linux/examples: TCPechod.c (multiple-process), TCPmechod.c (asynchronous I/O), TCPmtechod.c (multiple-thread), TCPtecho.c (asynchronous I/O). Using these programs, you can realize the communication between two computers for echo service.2) Write two echo client programs: TCPecho1.c and TCPecho2.c. TCPecho1.c uses multiple-thread while TCPecho2.c uses multiple-process.3) Test the responset time according to the usage of TCPtecho.c in the notes/textbook. Please record the time in the following tableTime Cost for Echo of _ Bytes ServerClientTCPechod.cTCPmtechod.cTCPmechod.cLocal RemoteLocalRemoteLocalRmoteTCPtecho.cTCPecho1.cTCPecho2.c4.3 Hints1) 先找到包含主函数main()的文件进行编译和连接,如果发现某些被调用函数没有找到,再把包含这些被调用函数的文件一起编译。2) 多个文件一起编译的办法有三个:一是gcc file1.c file2.c , 二是把包含被调用函数的文件用#include “file1.c”的方式包含在主函数文件中,三是建立一个工程,和VC+类似。3) 首先,通过浏览、编译、连接和运行别人的程序来学习编程;其次,尝试局部修改别人的程序来理解程序中每一个细节的含义;最后,编写自己的程序,其中可以使用别人的程序(段)。4) errno is defined in “errno.h”5) 多线程程序编译连接需要用-pthread选项5. Windows Socket Programming(验证性)Name: No.: Class: Grading:5.1 PurposeCompare the difference of the socket programming in Windows and Linux.5.2 Content1) Change TCPechod.c (multiple-process), TCPmechod.c (asynchronous I/O), TCPmtechod.c (multiple-thread), TCPtecho.c (asynchronous I/O), so that these programs can run on Windows. Test them between Windows and Linux. 2) Write a program to check whether or not current PC uses big-endian or little-endian.5.3 Hints1) 在课程主页”download”栏目上有程序可供参考。6. Advanced Socket Programming (设计性)Name1: No.: Class: Grading: Name2: No.: Class: 6.1 Purpose1. Learn to develop complex programs based on basic socket knowledge.2. Master the self-study method by learning network programming from literatures.6.2 ContentTwo students in a group are required to complete a tool hat contains the usage of socket programming.1) The programming language is not necessary C. You can choose C+, MFC, Perl, tcl/tk, python, PHP, ASP, JSP, Servlet, VB, ColdFusion, or others.2) The tool can be developed using socket programming or other middleware (e.g., RPC) based on socket programming. 3) The tool can follow a network protocol or not.4) The tool must be useful, e.g., network scanning, monitoring, downloading, gateway/proxy, chat, game. 5) This tool must be at least 1/3 different from any example in the textbook or other literatures. You are suggested to read more materials before this experiment.6) Two examples are gi

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论