




已阅读5页,还剩5页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
计算机网络实验报告班级:姓名: 学号:实验一一 实验目的及要求编写程序,模拟距离矢量路由算法的路由表交换过程,演示交换后的路由表的变化。二 实验原理距离矢量路由算法是这样工作的:每个路由器维护一张路由表(即一个矢量),它以网络中的每个路由器为索引,表中列出了当前已知的路由器到每个目标路由器的最佳距离,以及所使用的线路。通过在邻居之间相互交换信息,路由器不断地更新他们的内部路由表。 举例来说,假定使用延迟作为“距离”的度量标准,并且该路由器发送一个列表,其中包含了他到每一个目标路由器的延时估计值;同时,他也从每个邻居路由器接收到一个类似的列表。假设一个路由器接收到来自邻居x的一个列表,其中x(i)表示x估计的到达路由器i所需要的时间。如果该路由器知道他到x的延时为m毫秒,那么他也知道在x(i)+m毫秒之间内经过x可以到达路由器i。一个路由器针对每个邻居都执行这样的计算,就可以发现最佳的估计值,然后在新的路由器表中使用这个最佳的估计值以及对应的输出路线。三源程序:#include stdio.h#include stdlib.h#include malloc.h#include graphics.h#include dos.h#define VERNUM 7typedef struct int dis; int flag; int flag2;RoutNode; char tmp10;RoutNode dataVERNUMVERNUM; void welcome(); void InitRoutData(FILE* pfile); void PrintRoutData(); void SendInf(int recv, int send); void Exchange(); int main() int start, end, i, j, m, n; FILE *pfile; welcome(); pfile = fopen(1.txt, r); if (pfile = NULL) printf(the file wrong,press any key to come back.n); getch(); return; else InitRoutData(pfile); fclose(pfile); printf(nthe original route table:n); for (i = 0; iVERNUM; i+) printf(%c|, i + 65); for (j = 0; j 0) printf( , j + 65, dataij.dis); printf(n); PrintRoutData(); getch(); for (i = 0; i VERNUM; i+) for (m = 0; m VERNUM; m+) for (n = 0; n VERNUM; n+) datamn.flag = 0; Exchange(); PrintRoutData(); getch(); printf(nexchange the route table:n); return 0;void welcome() int gdriver=DETECT,gmode; registerbgidriver(EGAVGA_driver); initgraph( &gdriver, &gmode,C:Win-TC); cleardevice(); setbkcolor(CYAN); setviewport(0,0,639,479,1); clearviewport(); setbkcolor(BLUE); setcolor(14); rectangle(200,200,440,280); setfillstyle(1,5); floodfill(300,240,14); settextstyle(0,0,2); outtextxy(50,30,Distance Vector Routing Algorithm); setcolor(15); settextstyle(1,0,4); outtextxy(260,214,Welcome to use!); line(0,80,640,80); getch(); delay(300); cleardevice();void InitRoutData(FILE* pfile) char num10; int i = 0; char c; int m, n; fseek(pfile, 0, 0); for (m = 0; !feof(pfile) & m 7; m+) for (n = 0; !feof(pfile) & n = 0 & c = 9) | c = -) numi+ = c; /*end of else if*/ /*end of while*/ /*end of for (n = 0*/ /*end of for (m = 0*/void PrintRoutData() int i, j; for (i = 0; i VERNUM; i+) settextstyle(1,0,3); sprintf(tmp, %c,i + 65); outtextxy(i*80+50,130,tmp); outtextxy(10,160+i*40,tmp); for (j = 0; j VERNUM; j+) for (i = 0; i VERNUM; i+) if (dataij.dis =0) if(dataij.flag2 =1) setfillstyle(SOLID_FILL,5); bar(80*i+50,40*j+155,80*i+120,40*j+185); delay(50000); dataij.flag2 =0; setfillstyle(SOLID_FILL,3); bar(80*i+50,40*j+155,80*i+120,40*j+185); settextstyle(1,0,2); sprintf(tmp,%d,dataij.dis); outtextxy(80*i+65,40*j+165,tmp); /*end of for (j = 0*/ /*end of for (i = 0*/void SendInf(int recv, int send) int i; for (i = 0; i 0& datasendi.flag!=1) if (datarecvi.dis datasendi.dis + datarecvsend.dis) datarecvi.dis = datasendi.dis + datarecvsend.dis; datarecvi.flag =1; datarecvi.flag2 =1; /*end of if*/ /*end of for*/void Exchange() int i, j; for (i = 0; i VERNUM; i+) for (j = 0; j 0& dataij.flag!=1) SendInf(i, j); /*end of if*/ /*end of for (j = 0*/ /*end of for (i = 0*/四、 实验心得体会通过本次实验训练,我了解了距离矢量路由算法的基本原理,复习了C语言编程的内容,通过对路由算法的实现,加深了对路由表交换的理解。实验二一、 实验目的及要求编写程序,联系Socket编程和TCP/IP协议的应用,要求实现Server端和Client端的信息通信。 二、实验原理在TCP/IP编程中,为客户端和服务器端提供相同的端口号和IP地址号,实现Server端和Client端互联,运用Java文件流的知识,实现两端的信息传递。三、源程序/*ChatClient*/import java.awt.*;import java.awt.event.*;import java.io.*;import java.io.IOException;import .*;public class ChatClient extends FrameSocket s = null;DataOutputStream dos = null;TextField tf = new TextField();TextArea ta = new TextArea();public static void main(String args) new ChatClient().launchFrame();public void launchFrame() setLocation(400,300);this.setSize(300,300);add(tf,BorderLayout.SOUTH);add(ta,BorderLayout.NORTH);pack();tf.addActionListener(new tfListener();this.addWindowListener(new WindowAdapter() public void windowClosing(WindowEvent e) disconn();System.exit(0););setVisible(true);conn();public void conn () try s = new Socket(,5555);dos = new DataOutputStream(s.getOutputStream();System.out.println(客户端连接成功!); catch (UnknownHostException e) e.printStackTrace(); catch (IOException e) e.printStackTrace();public void disconn() try dos.close();s.close(); catch (IOException e) e.printStackTrace();private class tfListener implements ActionListener public void actionPerformed(ActionEvent e) String str = tf.getText().trim();ta.setText(str);tf.setText();try dos.writeUTF(str);dos.flush(); catch (IOException e1) e1.printStackTrace();/*ChatServer*/import java.io.IOException;import .*;import java.io.*;public class ChatServer public static void main(String args) boolean started = false;try ServerSocket ss = new ServerSocket(5555);started = true;while(started) boolean bConn = false;Socket s = ss.accept();bConn = true;System.out.println(一个客户端已连接);DataInputStream
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 第1课《消息二则-人民解放军百万大军横渡长江》说课稿 2024-2025学年统编版语文八年级上册
- 本册综合教学设计-2023-2024学年小学综合实践活动第12册人教版
- 第1课《 黑白装饰画》(说课稿)-2024-2025学年人美版(北京)(2023)八年级美术下册
- 平安银行武汉市汉阳区2025秋招笔试价值观测评题专练及答案
- 高新育才中学考试题及答案
- 高级智商考试题及答案大全
- 提高学生数学学习兴趣的作业设计策略
- 钢笔简笔画考试题及答案
- 自动控制原理实验教学中多元评价体系的构建与实施
- 跨学科团队协作能力培养策略
- 2025年度反洗钱阶段考试培训试考试题库(含答案)
- 收割芦苇施工方案
- 普通黄金现货购买合同8篇
- 三力测试考试题库及答案视频讲解
- 2025年河南省人民法院聘用书记员考试试题及答案
- 2025年中学教师资格考试《综合素质》核心考点与解析
- 口腔冠延长术
- 电力系统分析基础教案-按课时
- 动漫及动漫文化的定义
- 江苏亿洲再生资源科技有限公司资源综合利用技改提升项目 环评报告书
- 质量改进培训-课件
评论
0/150
提交评论