收藏 分享(赏)

计算机网络-网络程序设计.docx

上传人:dzzj200808 文档编号:2338816 上传时间:2018-09-11 格式:DOCX 页数:14 大小:156.36KB
下载 相关 举报
计算机网络-网络程序设计.docx_第1页
第1页 / 共14页
计算机网络-网络程序设计.docx_第2页
第2页 / 共14页
计算机网络-网络程序设计.docx_第3页
第3页 / 共14页
计算机网络-网络程序设计.docx_第4页
第4页 / 共14页
计算机网络-网络程序设计.docx_第5页
第5页 / 共14页
点击查看更多>>
资源描述

1、第 1 页广州大学学生实验报告开课学院及实验室:计算机科学与工程实验室 2014 年 12 月 13 日学院计算机科学与教育软件学院年级/专业/班姓名 学号实验课程名称 计算机网络实验 成绩实验项目名称网络程序设计 指导老师 熊伟1、程序演示使用苹果编程语言实现程序效果,模拟器运行结果如下:启动后画面第 2 页单击 C 机单击 C 后单击 D,显示结果第 3 页单击 A 后单击 C,显示结果2、程序设计思路根据网桥转发规则,我首先设计了 PC 类,代表主机。Bridege 类,代表网桥,实例方法包括一些数据帧转发,登记移除转发表等。Framing 类,代表数据帧,包括一些属性:目的地址,源地址

2、等。由于算法并不复杂,而且基于 ios 平台的开发本来就比较熟手,开发过程并没遇到什么困难。3、程序流程图第 4 页3、程序源代码由于篇幅有限,就不粘贴过多的代码。所有源代码压缩至附件上传。下面仅显示部分代码。Network 类,构建 UI 画面,并负责协调处理 PC,Bridge 直接数据的传递。第 5 页/ Network.m/ BridgeTransfer/ Created by Jeans on 12/14/14./ Copyright (c) 2014 Jeans. All rights reserved./#import “Network.h“#import “ShapeView.

3、h“#import “Bridge.h“#import “PC.h“#define AppSize UIScreen mainScreen.applicationFrame.size#define HorizontalSpacing 35#define VerticalSpacing 80#define kAnimationDuring 2interface Network()property (strong, nonatomic) PC *A;property (strong, nonatomic) PC *B;第 6 页property (strong, nonatomic) PC *C;

4、property (strong, nonatomic) PC *D;property (strong, nonatomic) Bridge *B1;property (strong, nonatomic) ShapeView *pathShapeView;property (strong, nonatomic) ShapeView *backgroundShapeView;property (strong, nonatomic) UILabel *resultLabel;endimplementation Network- (id)initWithFrame:(CGRect)frameif

5、(self = super initWithFrame:frame)/ self.backgroundColor = UIColor grayColor;/添加对象CGPoint pcPoint = CGPointMake(HorizontalSpacing, VerticalSpacing);self.A = self NewPCByOrigin:pcPoint;self.A.name = “A“;pcPoint.x += HorizontalSpacing + self.A.frame.size.width;第 7 页self bringSubviewToFront:self.A;self

6、.B = self NewPCByOrigin:pcPoint;self.B.name = “B“;pcPoint.x += HorizontalSpacing + self.B.frame.size.width;self.B1 = self NewBridgeByOrigin:CGPointMake(pcPoint.x, 10);pcPoint.x += HorizontalSpacing + self.B1.frame.size.width;self.B1.port1PCs = self.A,self.B;self.C = self NewPCByOrigin:pcPoint;self.C

7、.name = “C“;pcPoint.x += HorizontalSpacing + self.C.frame.size.width;self.D = self NewPCByOrigin:pcPoint;self.D.name = “D“;pcPoint.x += HorizontalSpacing + self.D.frame.size.width;self.B1.port2PCs = self.C,self.D;/绘制背景线CGFloat y = self.B1.frame.origin.y + self.B1.frame.size.height - 10;第 8 页UIBezier

8、Path *path = UIBezierPath bezierPath;path moveToPoint:CGPointMake(10, y);path addArcWithCenter:CGPointMake(10, y) radius:4.0 startAngle:0 endAngle:2*M_PI clockwise:YES;CGPoint p = CGPointMake(self.B1.frame.origin.x, y);path addLineToPoint:p;p.x += self.B1.frame.size.width;path moveToPoint:p;p.x = se

9、lf.frame.size.width - 10;path addLineToPoint:p;path addArcWithCenter:p radius:4.0 startAngle:0 endAngle:2*M_PI clockwise:YES;p.x = self.A.frame.origin.x+self.A.frame.size.width/2;path moveToPoint:p;path addLineToPoint:CGPointMake(p.x, VerticalSpacing);p.x = self.B.frame.origin.x+self.B.frame.size.wi

10、dth/2;path moveToPoint:p;path addLineToPoint:CGPointMake(p.x, VerticalSpacing);p.x = self.C.frame.origin.x+self.C.frame.size.width/2;path moveToPoint:p;path addLineToPoint:CGPointMake(p.x, VerticalSpacing);第 9 页p.x = self.D.frame.origin.x+self.D.frame.size.width/2;path moveToPoint:p;path addLineToPo

11、int:CGPointMake(p.x, VerticalSpacing);self.backgroundShapeView.shapeLayer.path = path.CGPath;self drawLineAnimation:self.backgroundShapeView.shapeLayer;return self;- (PC*)NewPCByOrigin:(CGPoint)aOriginPC *pc = (PC*)NSBundle mainBundleloadNibNamed:“PC“ owner:self options:nillastObject;pc.frame = CGRe

12、ctMake(aOrigin.x, aOrigin.y, pc.frame.size.width, pc.frame.size.height);pc.delegate = self;self addSubview:pc;return pc;- (Bridge*)NewBridgeByOrigin:(CGPoint)aOriginBridge *bri = (Bridge*)NSBundle mainBundleloadNibNamed:“Bridge“ owner:self options:nillastObject;bri.frame = CGRectMake(aOrigin.x, aOri

13、gin.y, bri.frame.size.width, bri.frame.size.height);self addSubview:bri;return bri;第 10 页- (ShapeView*)backgroundShapeViewif (!_backgroundShapeView)_backgroundShapeView = ShapeView allocinit;_backgroundShapeView.shapeLayer.fillColor = nil;_backgroundShapeView.shapeLayer.strokeColor = UIColor colorWi

14、thRed:0 green:0 blue:0 alpha:1.CGColor;_backgroundShapeView.shapeLayer.lineWidth = 1;_backgroundShapeView.shapeLayer.frame = self.bounds;_backgroundShapeView.shapeLayer addSublayer:self.A.layer;_backgroundShapeView.shapeLayer addSublayer:self.B.layer;_backgroundShapeView.shapeLayer addSublayer:self.

15、C.layer;_backgroundShapeView.shapeLayer addSublayer:self.D.layer;self.layer addSublayer:_backgroundShapeView.shapeLayer;return _backgroundShapeView;- (UILabel*)resultLabelif (!_resultLabel)_resultLabel = UILabel allocinitWithFrame:CGRectMake(self.B1.frame.origin.x+self.B1.frame.size.width/2 - 250,20

16、0,500,50);_resultLabel.textAlignment = NSTextAlignmentCenter;第 11 页_resultLabel.backgroundColor = UIColor clearColor;self.backgroundShapeView.shapeLayer addSublayer:_resultLabel.layer;return _resultLabel;#pragma mark - 画线-(void)drawLineAnimation:(CALayer*)layerCABasicAnimation *bas = CABasicAnimatio

17、n animationWithKeyPath:“strokeEnd“;bas.duration = kAnimationDuring;bas.delegate = self;bas.fromValue = 0.0;bas.toValue = 1.0;layer addAnimation:bas forKey:“key“;#pragma mark - PC Delegate- (void)PCPressed:(PC *)aPCself.resultLabel.text = self.B1 addOrRemovePC:aPC;endBridge 类,网桥类,根据网桥转发规则实现转发功能,并输出对应

18、文字提示。/第 12 页/ Bridge.m/ BridgeTransfer/ Created by Jeans on 12/14/14./ Copyright (c) 2014 Jeans. All rights reserved./#import “Bridge.h“#import “PC.h“interface Bridge()property (strong, nonatomic) NSMutableArray *currentPCs;endimplementation Bridge- (id)initWithCoder:(NSCoder *)aDecoderif (self = su

19、per initWithCoder:aDecoder)self customInit;return self;- (id)initWithFrame:(CGRect)frame第 13 页if (self = super initWithFrame:frame)self customInit;return self;- (void)customInit- (NSMutableArray*)currentPCsif (!_currentPCs)_currentPCs = NSMutableArray allocinit;return _currentPCs;- (NSString*)addOrR

20、emovePC:(PC *)aPCNSString *string = nil;if (self.currentPCs containsObject:aPC)self.currentPCs removeObject:aPC;elseself.currentPCs addObject:aPC;string = NSString stringWithFormat:“%“,aPC.name;if (self.currentPCs.count = 2)第 14 页PC *p1 = self.currentPCs0;PC *p2 = self.currentPCs1;/转发string = NSStri

21、ng stringWithFormat:“% “,p1.name,p2.name;if (self.port1PCs containsObject:p1 else if (self.port2PCs containsObject:p1 elseif (self.port1PCs containsObject:p1)string = string stringByAppendingFormat:“网段 1:% 发往 网段 2:% 成功“,p1.name,p2.name;elsestring = string stringByAppendingFormat:“网段 2:% 发往 网段 1:% 成功“,p1.name,p2.name;self.currentPCs removeAllObjects;return string;end

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 高等教育 > 大学课件

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报