![毕业设计论文外文文献翻译_第1页](http://file4.renrendoc.com/view/3af31355264765df1c35d02ddd3b56ac/3af31355264765df1c35d02ddd3b56ac1.gif)
![毕业设计论文外文文献翻译_第2页](http://file4.renrendoc.com/view/3af31355264765df1c35d02ddd3b56ac/3af31355264765df1c35d02ddd3b56ac2.gif)
![毕业设计论文外文文献翻译_第3页](http://file4.renrendoc.com/view/3af31355264765df1c35d02ddd3b56ac/3af31355264765df1c35d02ddd3b56ac3.gif)
![毕业设计论文外文文献翻译_第4页](http://file4.renrendoc.com/view/3af31355264765df1c35d02ddd3b56ac/3af31355264765df1c35d02ddd3b56ac4.gif)
![毕业设计论文外文文献翻译_第5页](http://file4.renrendoc.com/view/3af31355264765df1c35d02ddd3b56ac/3af31355264765df1c35d02ddd3b56ac5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、 m工多次毕业设计(论文)外文参考文献翻译计算机科学与信息工程系系(院)2008 届题 目企业即时通Instant Messaging for Enterprises课题类型技术开发课题来源自选学生姓名许帅 专业班级 04计算机科学与技术指导老师王占中 职 称 工程师完成日期: 2008年4月 6日目录 TOC o 1-5 h z HYPERLINK l bookmark6 o Current Document Instant Messaging for Enterprise1Tips1. HYPERLINK l bookmark9 o Current Document Introductio
2、n1. HYPERLINK l bookmark11 o Current Document First things first2. HYPERLINK l bookmark13 o Current Document The While-Accept loop4. HYPERLINK l bookmark15 o Current Document Per-Thread class6. HYPERLINK l bookmark17 o Current Document The Client class7. HYPERLINK l bookmark19 o Current Document 企业即
3、时通9.提示 9.简介 9 HYPERLINK l bookmark21 o Current Document .首先第一件事 10 HYPERLINK l bookmark23 o Current Document .监听循环 11.单线程类 13 HYPERLINK l bookmark25 o Current Document .用户端类 14Instant Messaging for EnterpriseTipsIf Java is, in fact, yet another computer programming language, you may question why it
4、is so important andwhy it is being promoted as a revolutionary step in computer programming. The answer isn t imme(if you re coming from aatritional programming perspective. Although Java is very useful for solving traditional standalone programming problems, it is also important because it will sol
5、ve programming problems on the World Wide Web. What is the Web?The Web can seem a bit of a mys tery at first, with all this talk of“ presenfteg, and home pages.”It s helpful to step back and see what it really is, but to do this you must understand client/server systems, another aspect of computing
6、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
7、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 expe
8、rience doing networking programming. We 1l 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 prog
9、ramming 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.IntroductionWell also examine s
10、ome 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
11、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 wi
12、ll 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 lev
13、el 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.W
14、hat 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 pro
15、cess 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
16、 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 serviceso However, our example is going to stand all by itself. It will take care of all
17、networking responsibilities on its own. As well see, this isnt very hard.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
18、that often a single machine might serve as a Web server, a chat server, an FTPserver, 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 i
19、nternal 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 Prot
20、ocol) 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,
21、 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
22、.)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
23、 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.
24、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
25、the port # from the command lineint port = Integer.parseInt( args0);/ Create a Server object, which will automatically begin/ accepting connections.new Server( port ); 现在我们开始监听,下一节我们将继续介绍是如何接受连接的,看看我们是如何处理它 们的。我们已经准备从我们的客户接受连接,这就是说料体内是如何进行的。.监听循环上面我们提到了 java中一个叫做套接字的对象,它代表着通过建立从别的地方的应用程 序接收数据。一个客户端从
26、定义,启动到连接服务器,我们是怎么得到这个socket的呢?服务器端首 先要做的工作是等待连接的建立,也就是说我们需要发送一些信息到客户端,代表着连接的 建立。这就是serversocket 是如何工作的,有一个 serversocket 对象,它一直监听着一个端 口,当有一个新的连接到来的时候,它将创建一个socket对象代表着连接的建立。接受socket可能你服务器程序是为了服务来自互联网上的很多客户端,这些客户端将彼此不相关的 与你的服务器建立连接,也就是说我们不能控制客户端连接到来的时间和顺序,下面我们将 介绍多线程一个比较优越的方法处理这些连接不管他们什么时候到来。但是当连接到来时我
27、们将试图处理这个连接。Socket暗含了一个简单直接的处理方法:它串行接受连接,正如你一个挨一个的问他们一样,而它们专门在排着队等待。下面就是模 型:/ start listening on the portServerSocket ss = new ServerSocket( port );/loop foreverwhile (true) / get a connectionSocket newSocket = ss.accept();/ deal with the connection/ . 当serversocket的方法调用时,accept()实例将返回一个socket对象代表着新的
28、连接 的建立,这次连接处理完毕,将再次调用accpt ()处理下一个连接,就是用这种方法,不管连接到来的有多快,不管你的计算机有多少处理器和网络接口,一个时刻只能建立一个连 接(如果一时间没有连接请求,accpet ()实例将一直等待,知道有连接来请求。一般来说,系列化是一个有效处理事情同时发生的一个有效的方法,但是它的一个潜在 的缺点是消除了排比,也就是说,串行化阻止了我们在同一时间做很多的事情。上面的代码,当程序处理一个连接的时候,其他的连接是必须等待的。但是对我们来说系列化已经不是一个问题,因为每次连接到来的时候,我们将建立一个 新的线程来处理它。一旦线程创建,它将去处理新的连接,我们的
29、循环接受accept ()将去等待接收新的连接。如果建立线程的速度够快,连接将不会被阻塞。代码:然我们看看代码做的这些,下面的代码涉及到我们谈论的东西,监听一个端口,接收连 接,并且创建新的线程处理它们。下面它们将做一些有用的东西,让我们看看:private void listen( int port ) throws IOException / Create the ServerSocketss = new ServerSocket( port );/ Tell the world were ready to goSystem.out.println( Listening on +ss );
30、/ Keep accepting connections foreverwhile (true) / Grab the next incoming connectionSocket s = ss.accept();/ Tell the world weve got itSystem.out.println( Connection from +s );/ Create a DataOutputStream for writing data to the/ other sideDataOutputStream dout = new DataOutputStream( s.getOutputStre
31、am();/ Save this stream so we dont need to make it againoutputStreams.put( s, dout );/ Create a new thread for this connection, and then forget/ about itnew ServerThread( this, s );代码的最后一行创建了一个线程处理新的连接。对于serverthread ,这是该课题的下一节。.单线程类什么是thread?Java语言的两个主要优势是网络和多线程。这并不是说其他语言,不支持这些功能,其实其他语言也支持这些功能。但是ja
32、va用来提供这些功能非常优雅,特别是作为一种商业语 言。一个线程是一般定义为一个单独的控制线,它的真正意思是说一个多线程的程序包含有 多个活动在同时进行。除了多线程是在一个程序里共享数据资源以外,它类似任务和多任务处理的概念。这使 它们共享数据直接高效,但也使它们更容易相互混淆。为什么要使用多线程?详细讨论多线程超出了补习的范围,虽然你在程序中使用线程的原因不只一个,但最重 要的原因是是要建造一个输入输出的聊天服务器。你的聊天服务器和客户端的用户沟通,用户通常情况下要比服务器慢的多,也就是说服 务器端要浪费很多的时间等待用户发送消息。而我们又不知道谁先发送消息,如果使用单线 程,只有等到0号用
33、户先发送消息然后才轮到1号到10的用户发送。由于这个原因,我们为每一个用户建立一个连接系统的线程。多线程的优点是:当一个 线程等待用户缓慢发送消息时,他基本上是处于休眠状态,直到那个用户发送消息。于此同 时,另外一个线程可以接受其他用户发过来的消息。实际上,多线程让我们彼此之间尽可能 的迅速。在java程序中,任何一个类可以实现一个线程通过继承runable ()接口来实现。可以通过java.lang.Thread 来查询。我们只有选择后者。public class ServerThread extends Thread/ .Socket对象是必不可少的,因为线程的目的是用socket来让通信
34、的双方进行通信的。下面是代码:/ Constructor.public ServerThread( Server server, Socket socket ) / Save the parametersthis.server = server;this.socket = socket;/ Start up the thread start();.用户端类既然我们到了要讨论用户的时候了,我们应该说一下我们的通信协议。每一个客户机/服务器系统有一个通信协议,这无疑是发送和接受消息的一种形式。协议是如此的简单几乎 不值得命名。或者它已经以一种复杂的标准发布到世界各地,无论是哪种方式,它就是一项 协议。我们将建立自己的协议,因为这对于java语言来说是很简单的。我们不能从现有的标准 中得到什么,我们只有建立非常简单的协议。Java语言有一对非常有用的类 datainputstream 和dataoutputstream 。这些类允许你 读入和写出各种类型的数据到流中,不用考虑它们将被写到哪里,因为这些类使用的是相同 的格式,并且这种格式是不改变的。你可以确定一个整形的数据被写到 DataOutputStream中 并且这个整形数据可以从另外一端的 DataInputStream读出来。下面就是我们的协议:当用户把一些信息输入到聊天窗口时,输入的信息就像一用字符输入到
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 畜牧养殖综合解决方案
- 中医科常用操作规范
- 中班科学教案水中的秘密
- 中班科学教案水中的秘密
- 中旬天津市静海区北师大实验学校自聘教师招聘笔试真题2022
- 厦门颐居城市服务有限公司招聘笔试真题2022
- 2023年昆明市官渡区小板桥中学教师招聘考试真题
- 安徽长泰科技有限公司社会招聘笔试真题2022
- 工业研发与应用推广计划制定
- 多式联运中高效配送与仓储管理的优化实践
- 2024-2030年中国个人护理机器人行业市场发展趋势与前景展望战略分析报告
- 江苏省南京市玄武区2023-2024学年八年级下学期期末语文试题(含答案解析)
- 学校建大门合同协议书
- 2024-2030年中国超市行业发展趋势与前景展望战略分析报告
- 2024年甘肃高考地理试卷(真题+答案)
- 江苏苏州昆山2022-2023学年小升初考试数学试卷含答案
- 氧气吸入法表格97
- 骨科临床诊疗指南与技术操作规范
- 常用灯具的利用系数表讲解学习
- 新概念英语1偶数课文.doc
- 500立方事故罐施工组织设计
评论
0/150
提交评论