




已阅读5页,还剩13页未读, 继续免费阅读
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
毕业设计(论文)外文参考文献翻译 计算机科学与信息工程系 系(院) 2008 届题 目 企 业 即 时 通 Instant Messaging for Enterprises 课题类型 技术开发 课题来源 自 选 学生姓名 许帅 专业班级 04计算机科学与技术 指导老师 王占中 职 称 工程师 完成日期: 2008年 4 月 6 日16目 录Instant Messaging for Enterprise11. Tips12. Introduction13. First things first24.The While-Accept loop45. Per-Thread class66. The Client class7企业即时通91.提示92.简介93.首先第一件事104.监听循环115.单线程类136.用户端类14Instant Messaging for Enterprise1. TipsIf Java is, in fact, yet another computer programming language, you may question why it is so important and why it is being promoted as a revolutionary step in computer programming. The answer isnt immediately obvious if youre coming from a traditional programming perspective. Although Java is very useful for solving traditional standalone programming problems, it is also important because it will solve programming problems on the World Wide Web. What is the Web?The Web can seem a bit of a mystery at first, with all this talk of “surfing,” “presence,” and “home pages.” Its helpful to step back and see what it really is, but to do this you must understand client/server systems, another aspect of computing that is full of confusing issues. The primary idea of a client/server system is that you have a central repository of information, some kind of data, often in a database。That you can distribute on demand to some set of people or machines. The basic concept of client/server computing, then, is not so complicated. The problems arise because you have a single server trying to serve many clients at once.Building a java chat serverShould I take this tutorial?in this tutorial, we will build both the server and client sides of a simple chat system this tutorial is for someone with little or no experience doing networking programming. Well cover topics such as networking and multithreading in enough detail so that youll be able to follow the examples, even if you have little or no experience doing this kind of programming. You will, however, need to be familiar with basic object-oriented programming in the Java language. In this tutorial, youll build a simple, centralized, connection-oriented Java server. In doing so, youll learn a basic framework that you can use when creating such a server, using time-honored techniques that work well in many situations.2. IntroductionWell also examine some of the limitations of this framework and explore ways of getting around them.What is a connection-oriented server?Generally speaking, the job of any server is to provide a centralized service. However, there are many different ways of providing services, and many different ways to structure the communications. Chat is roughly described as a connection-oriented service, because a user establishes a connection and maintains that connection, sending and receiving text for the duration of the session. Well be creating a stripped-down, connection-oriented server. Learning the basic framework will help you a great deal in creating other connection-oriented servers in the future.Why create from scratch?In creating this prototype server, well be using nothing more than the basic packages built into every Java implementation. This allows us to explore server programming at the very lowest level possible in the Java language.There are certainly many systems available that can take care of many of these networking details for you. In many cases, the best real-world solution is to use an existing framework, because it often provides useful features such as fault-tolerance, load-balancing.What does the server do?Before we describe the Listener class, well describe the server. Doing so has a certain chronological elegance, because in our running system, the server will have to start before any of the clients can connect to it.Our server will be a stand-alone program - a single Java process running on its own machine. It wont require any support software other than a Java virtual machine. And it wont require a Web server or application server, although a Web server or application server will likely be used to serve the client applet to the client.More advanced server systems often embed the server code within a larger framework. This framework might be used to supply features such as load balancing, special libraries for handling large numbers of clients, process migration, and database services。However, our example is going to stand all by itself. It will take care of all networking responsibilities on its own. As well see, this isnt very hard.3. First things firstListening on a portThe first thing we have to do is to get ready to receive incoming connections. To do this, we must listen on a port.A port can be thought of as an address within a single computer. Remember that often a single machine might serve as a Web server, a chat server, an FTP server, and several other kinds of servers at the same time. Because of this, a connection to a server needs to specify not only the address of the machine itself, but also the particular service within the machine. This internal address is a port and is represented by a single integer between 1 and 65535.SocketsOur communications between client and server will pass through a Java object called a Socket. Sockets are not at all Java-specific; the term is taken directly from the terminology of general IP (Internet Protocol) network programming. In Java programs, a Socket object is simply a wrapper around the low-level。The most important thing to know about a Socket object is that it contains (among other things) two Streams. One is for reading data coming in, and the other is for writing data out.That is to say, a Socket has an InputStream and an OutputStream.(If these Stream classes are unfamiliar to you, then suffice it to say that they are objects used for reading and writing data, often as a stream of bytes. If you dont know about them yet,you really should. See the java.io package for more information.)So, now we get to the first of our seven elements, the Listener Class. Well call it Server.java.The next few panels will show the essential elements of this class: the constructor and the main() routine.The constructor for Server takes a single parameter - a port number. This tells us what port to listen on when we are ready to start accepting connections. Here is the constructor:public Server( int port ) throws IOException / All we have to do is listenlisten( port );The main() routineWell also include a main() routine so that this Server class can be used as its own stand-alone application. In practice, you might be embedding your basic server code in something larger, in which case you already have a main(). But for our purposes, the Server is all there is. Heres the main() routine:/ Main routine/ Usage: java Server portportstatic public void main( String args ) throws Exception / Get the port # from the command lineint port = Integer.parseInt( args0 );/ Create a Server object, which will automatically begin/ accepting connections.new Server( port ); 现在我们开始监听,下一节我们将继续介绍是如何接受连接的,看看我们是如何处理它们的。我们已经准备从我们的客户接受连接,这就是说料体内是如何进行的。4.监听循环上面我们提到了java中一个叫做套接字的对象,它代表着通过建立从别的地方的应用程序接收数据。一个客户端从定义,启动到连接服务器,我们是怎么得到这个socket的呢?服务器端首先要做的工作是等待连接的建立,也就是说我们需要发送一些信息到客户端,代表着连接的建立。这就是serversocket是如何工作的,有一个serversocket对象,它一直监听着一个端口,当有一个新的连接到来的时候,它将创建一个socket对象代表着连接的建立。接受socket可能你服务器程序是为了服务来自互联网上的很多客户端,这些客户端将彼此不相关的与你的服务器建立连接,也就是说我们
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年法医学法医鉴定技能评价试题答案及解析
- 2025年妇产科护理学妇产科常见问题护理技能考核试卷答案及解析
- 2025-2030动力总成电控系统软件开发的功能安全认证报告
- 2025-2030功能性食品原料创新开发方向与消费者健康诉求契合度报告
- 2025-2030功率半导体器件在新能源发电系统中的失效模式与可靠性提升报告
- 2025-2030共享经济平台市场全面调研及商业模式与投资风险评估报告
- 2025-2030共享充电桩运营风险防控与用户体验提升策略报告
- 新能源产业2025:技术创新与知识产权运营政策影响分析报告
- 2025年高速公路沿线光储充一体化项目规划与管理报告
- 2025年工业机器人柔性制造系统应用技术创新报告
- 安徽省花凉亭灌区“十四五”续建配套与现代化改造工程环境影响报告书
- 铁路行李包裹运价表(铁路旅客运输规程)
- 2023浙江金华市义乌市机关事业单位编外聘用人员招聘101人笔试备考题库及答案解析
- 医院护理部人员绩效考核标准及评分细则
- 师范大学新生服务手册
- 第九组 生态监测与评价
- 西方国家的宪法制度课件
- 2021年色达县林业系统事业单位招聘考试《林业基础知识》笔试试题及答案解析
- 抢救车药品每月检查登记表
- 食品销售流程图
- 国家职业技能标准 (2021年版) 燃气供应服务员
评论
0/150
提交评论