欢迎来到天天文库
浏览记录
ID:56014455
大小:70.00 KB
页数:21页
时间:2020-03-15
《java服务器与客户端源码.doc》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、服务器(server)1类ServerTest1类ChatClient2类MyQueue3类ReceiveFromClient4类SendToClientThread11客户端(client)12类StudentWindow12类StudentDuQu15类ClientTest19类BaoCunJiLu20服务器(server)类ServerTestpackageServer_System;importjava.io.IOException;importjava.net.ServerSocket;importjava.net.Socket;i
2、mportjava.util.Vector;importClient_System.TeacherWindow;publicclassServerTestextendsThread{privateintnumber;privateVectorallClient=newVector();privateMyQueuechatCon=newMyQueue();publicServerTest(intnumber){this.number=number;this.start();}publicvoidrun(){ServerSocketserver=
3、null;try{server=newServerSocket(number);}catch(IOExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}newSendToClientThread(chatCon,allClient);while(true){try{Socketss=server.accept();ChatClientcc=newChatClient(ss);//System.out.println(cc.toString());allClient.a
4、dd(cc);//Stringname=ss.getInetAddress().toString();chatCon.offer(cc.IP+"来聊天了。。。");newReceiveFromClient(cc,chatCon,allClient);}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}}类ChatClientpackageServer_System;importjava.io.BufferedReader;importjava.io.I
5、OException;importjava.io.InputStreamReader;importjava.io.OutputStream;importjava.io.PrintStream;importjava.io.Reader;importjava.net.Socket;importMysql_System.User;publicclassChatClient{publicSocketso;publicStringIP;publicPrintStreamout;publicBufferedReaderin;publicChatClien
6、t(Socketso)throwsException{this.so=so;Readerr=newInputStreamReader(so.getInputStream());in=newBufferedReader(r);OutputStreamos=so.getOutputStream();out=newPrintStream(os);IP=so.getInetAddress().toString();}//把聊天信息发到客户端publicvoidsendToClient(Stringword){out.println(word);out
7、.flush();}//从客户端读聊天信息publicStringreadFromClient()throwsException{Stringstr=null;try{str=in.readLine();}catch(Exceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}//System.out.println(str);returnstr;}}类MyQueuepackageServer_System;importjava.util.LinkedList;publiccl
8、assMyQueue{privateLinkedListl=newLinkedList();publicbooleanoffer(Objecte){returnl.
此文档下载收益归作者所有