已阅读5页,还剩2页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
专业: 姓名: 学号: 日期: 地点: 实验报告课程名称: 计算机网络 指导老师: 成绩:_实验名称: 实验类型: 同组学生姓名:_一、实验目的和要求(必填)二、实验内容和原理(必填)三、主要仪器设备(必填)四、操作方法和实验步骤五、实验数据记录和处理六、实验结果与分析(必填)七、讨论、心得装 订 线一、实验目的和要求开始使用套接字编程逐步熟悉Winsock完成一个简单的Web server二、实验内容和原理 阅读教材和PPT学习老师提供的winsock编程资料安装相应的开发环境三、主要仪器和设备Java四、操作方法和实验步骤Stage 1 The echoer Simply sends back & displays the contents of the received data stream from the client Using telnet to test your echoer. Run cmd telnet your_ip your_port type in random characters & check quitjava程序:import java.io.*; import .*; public class TCPServer public static void main(String argv) throws Exception System.out.println(start); String clientSentence; /读写语句 String serverSentence; /发送语句 ServerSocket welcomeSocket = new ServerSocket(6789); /建立套接字,端口6789 while(true) Socket connectionSocket = welcomeSocket.accept(); /建立发送套接字 BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream(); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); outToClient.writeBytes(Server has started!rn); clientSentence = inFromClient.readLine(); outToClient.writeBytes(Have received: ); serverSentence = clientSentence + n; outToClient.writeBytes(serverSentence); /send back the message connectionSocket.close(); /关闭套接字 对套接字运行测试:Stage 2Paser Functionality1. Check whether the message is a HTTP GET request message.2. If not, send back Bad request string.3. If so, find out the of the file the client is requesting.4. Check if the file, , exists.5. If not, send back File not existed string6. If so, send back1. File found string2. File size: stringJava程序:import java.io.*; import .*; public class WEBServer public static void main(String argv) throws Exception String clientSentence; String capitalizedSentence=null; String request=new String(GET); long size; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream(); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); clientSentence = inFromClient.readLine(); String word = clientSentence.split( ); if(request.equals(word0) String name = word1.split(/); File file = new File(name1); if(file.exists() size = file.length(); capitalizedSentence = File found+File size:+size; else capitalizedSentence = (File not existed); else capitalizedSentence = Bad request; outToClient.writeBytes(capitalizedSentence); connectionSocket.close(); 输入:http:/localhost:6789/test.html输入http:/localhost:6789/tst.htmlStage3 the responderWeb Server Functionality1. Check whether the message is a GET message.2. If not, send back Bad request string.3. If so, find out the of the file the client is requesting.4. Check if the file, , exists.5. If not, send back File not existed string6. If so, send back an HTTP Response with the fileJava 程序:import java.io.*; import .*; public class WEBServer public static void main(String argv) throws Exception String clientSentence; String capitalizedSentence=null; String request=new String(GET); long size; ServerSocket welcomeSocket = new ServerSocket(6789); while(true) Socket connectionSocket = welcomeSocket.accept(); BufferedReader inFromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream(); DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream(); clientSentence = inFromClient.readLine(); String word = clientSentence.split( ); if(request.equals(word0) String name = word1.split(/); File file = new File(name1); if(file.exists() FileInputStream content = new FileInputStream(file); byte data = new bytecontent.available(); content.read(data); content.close(); FileOutputStream content1 = new FileOutputStream(file); content1.write(data); content1.close(); size = file.length(); capitalizedSentence = HTTP/1.0 200 Document Followsrn+Content-Length:+size+rnrn+new String (data); else capitalizedSentence = (File n
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2026陕西西安西京初级中学教师招聘备考题库含答案详解(轻巧夺冠)
- 2026福建龙岩学院附属中学招聘心理健康教师的1人备考题库含答案详解(典型题)
- 2026年山东师范大学第二附属中学第二批公开招聘人员备考题库(4名)附答案详解(达标题)
- 2026河北秦皇岛市市直医疗卫生单位第二批招聘工作人员36人备考题库附答案详解
- 2026年马鞍山市和县文化旅游体育局度校园招聘备考题库带答案详解(完整版)
- 2026浙江丽水莲都电信业务项目部招聘智家工程师6人备考题库含答案详解(培优)
- 2026浙江宁波前湾新区招聘事业编制教师(第四批)24人备考题库及答案详解(名师系列)
- 2026青海海南州贵南县文化馆演职人员招聘4人备考题库及1套完整答案详解
- 2026北京顺义区卫生健康人才服务中心第一批招聘编外工作人员1人备考题库含答案详解(典型题)
- 2026陕西西安市未央区辛家庙社区卫生服务中心招聘4人备考题库及答案详解(各地真题)
- 2026年急性缺血性卒中患者早期管理-美国心脏协会指南
- 2026年台州临海市粮食收储有限公司招聘工作人员5人建设笔试备考题库及答案解析
- DB42∕T 1528-2026 湖北省农业用水定额
- 2026年两会政府工作报告精神宣讲《聚焦两会关注民生》
- 船舶代理公司考核制度
- 2025年建信期货招聘笔试真题及答案
- 2025年北京纪委监委公开遴选公务员笔试试题及答案解析
- GMP计算机系统用户权限管理操作规程
- 2025年7月陕西省普通高中学业水平合格性考试语文试题及答案
- 2025河南编导考试真题及答案
- DB44 07∕T 70-2021 地理标志产品 新会陈皮
评论
0/150
提交评论