欢迎来到天天文库
浏览记录
ID:15388434
大小:25.50 KB
页数:10页
时间:2018-08-03
《java 网络编程 聊天室 网络编程聊天室》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、java网络编程聊天室网络编程聊天室导读:就爱阅读网友为您分享以下“网络编程聊天室”资讯,希望对您有所帮助,感谢您对92to.com的支持!packageweb;importjava.io.BufferedReader;importjava.io.IOException;importjava.io.InputStream;importjava.io.InputStreamReader;importjava.io.OutputStream;importjava.net.Socket;importjava.util.Arrays;publi
2、cclassClient1{publicstaticvoidmain(String[]args){try10{Socketsocket=newSocket(“niit3010”,8080);System.out.println(“connected”);InputStreaminputStream=socket.getInputStream();OutputStreamoutputStream=socket.getOutputStream();InputStreamReaderisr=newInputStreamReader(input
3、Stream);intread;while((read=isr.read())!=-1){charc=(char)read;System.out.println(read);System.out.println(c);}//intcount;//char[]cbuf=newchar[10];//while((count=isr.read(cbuf))!=-1){//System.out.println(count);//for(charc:cbuf){//System.out.println(c);//}//10}//BufferedR
4、eaderreader=newBufferedReader(isr);//Stringline=reader.readLine();//System.out.println(line);System.out.println(“end”);}catch(IOExceptione){//TODOAuto-generatedcatchblocke.printStackTrace();}}}packageweb;importjava.awt.event.ActionEvent;importjava.awt.event.ActionListene
5、r;importjava.io.IOException;importjava.net.Socket;importTest.SendMessage;10publicclassClient2implementsIReceiver{publicSendMessagesm;@Overridepublicvoidreceive(Stringline){System.out.println(line);}publicstaticvoidmain(String[]args){Client2client2=newClient2();client2.sm
6、=newSendMessage();try{Socketsocket=newSocket(“127.0.0.1”,8080);Transfertransfer=newTransfer(socket);transfer.setReceiver(newClient2());transfer.send(“hello”);}catch(IOExceptione){//TODOAuto-generatedcatchblock10e.printStackTrace();}}}packageweb;publicinterfaceIReceiver{v
7、oidreceive(Stringline);}packageweb;importjava.io.IOException;importjava.io.InputStream;importjava.io.OutputStream;importjava.io.PrintStream;importjava.net.ServerSocket;importjava.net.Socket;publicclassServer1{publicstaticvoidmain(String[]args){try{ServerSocketss=new10Ser
8、verSocket(8080);Socketsocket=ss.accept();System.out.println(“connected”);InputStreaminputStream=socket.
此文档下载收益归作者所有