您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 广告经营 > 基于Java-Socket通信程序设计
辽宁工程技术大学毕业设计(论文)I摘要随着时代的发展,人们互相交流的方式也在逐渐变化,从原来的面对面,到电话、手机,然后到短信、E-mail,再到现在的QQ、微信,聊天变得越来越具有实时性和有效性。但是现在聊天软件都必须连接到Internet后才能够让人们相互交流。如果用户在工作时候连接网络,有可能因为网络的关系使得工作效率变低;也有可能因为网络的关系,让公司内部的资料被泄露出去,使公司收到损失。因此进行一个在局域网下的聊天工具的设计是很有必要的。本文介绍了在局域网内实现相互收发消息的基本流程,并且编写了一个基于Socket的聊天窗口。这个简单的软件采用的是C/S结构模式,即客户端/服务器模式。这个软件可以让客户端和客户端能够进行通信,服务器端也能够对客户端进行发消息,还能够进行监听客户端的所有消息。不足之处是只能够启动一个服务器,所有的客户端只能够通过一个端口连接服务器进行通信。如果让客户端不看到不属于这个端口的其它客户发的消息,必须重新定义Server端,更改端口。本文用到了Sock编程、多线程、TCP/IP协议还有图形界面设计的控件编程的知识。通过对程序进行测试,发现程序能够在同一个局域网下实现多人通信。我们也许通过路由器分配的IP,也可以利用现在流行的“免费WiFi”,让所有人连接WiFi,这样,也会给每个客户端分配IP地址,这样也就有了局域网,它并不需要外网的帮助。关键词:局域网;Socket;多线程;TCP/IP常城:基于Java_Socket通信程序设计IIAbstractWiththedevelopmentofthetimes,thecommunicationmodeofpeopleischangedgradually.Yesterday,wecommunicatedwitheachotherfacetoface,thenwetellsomethingtoothersusingtelephone,cellphone,andthenusingmessage,e-mail.NowwetellsomethingtoeachotherwithQQ,MSNandwechat.Communicationbecomesmoreandmorereal-timeandephemeral.ButthesoftwareweusedshoulddependontheInternet.Ifnot,theyarenothing.IfweconnecttheInternentduringworking,wemaynotdevoteourselfintoourjobs.Andalso,theimportantinformationmaybeleakedtoletthecompanylostmoney.SoitisimportanttodesignasoftwareaboutchatingintheLANbutnotontheInternet.Thispaperintruducethatpeoplesendmessagestoeachotherinthelocalareanetwork.AndProgrammingthechatwindowbasedontheSocket.ThissimpleapplicationusetheC/Smodel.TheC/SmodelisClient/Servermodel.Thisapplicationcanletthedifferentclientsendsorreceivesmessages.Servercansendmessagetoeveryclientanditcangetallmessagesofeveryclientsends.Thereisaweakpointthatpeoplecanjuststartoneserver.Allclientsshouldusetheporttheservergiven.Ifwewanttodividepeople,weshouldchangetheportandcopyanother“Server”codetostartnewserver,thensomepeopleusethisserverandothersuseanotherserver.ThispaperusestheknowledgesabouttheSocketprogramming,multithreading,TCP/IPprotocolandthecontrolprogrammingabouttheGUI.Whentested,theapplicationcanletmulticlientssendorreceivemessages.WemayusetheIPthattheroutergivesus,wecanalsousethe“Free-WiFi”thatispopularnowtoleteveryoneconnecttheWiFi,theneverybodyhasoneIP.PeoplehavealocalareanetworkanditdoesnotneedtheInternet.Keywords:LocalAreaNetwork;Socket;Multithreading;TCP/IP辽宁工程技术大学毕业设计(论文)目录引言.............................................................................................................11实现原理...............................................................................................21.1C/S结构...............................................................................................21.2TCP/IP协议.........................................................................................41.3套接字..................................................................................................51.4多线程..................................................................................................61.5Socket的同步和异步方式..................................................................81.6用Socket开发的C/S模型.................................................................82总体设计...............................................................................................92.1程序实现原理.....................................................................................92.2C/S架构设计.....................................................................................102.3数据流图............................................................................................113模块设计.............................................................................................123.1系统的总体流程图............................................................................123.3上传文件.............................................................................................143.4下载文件.............................................................................................153.5服务器和客户端图形界面的的详细设计.......................................173.6服务器等待连接的详细设计...........................................................203.7监听端的详细设计...........................................................................213.8客户端发送消息内容以及连接服务器程序...................................223.6获得客户端ip...................................................................................224系统测试.............................................................................................234.1聊天程序测试...................................................................................23常城:基于Java_Socket通信程序设计44.2上传与下载程序测试.......................................................................26致谢...........................................................................................................28参考文献...................................................................................................29附录A.......................................................................................................30附录B.......................................................................................................43辽宁工程技术大学毕业设计(论文)1引言近年来,随着科技的不断进步,网络也在快速向前发展着。企业为了高效迅速并且安全地处理各种事情,它们越来越多地使用局域网来工作而不用
本文标题:基于Java-Socket通信程序设计
链接地址:https://www.777doc.com/doc-7183480 .html