欢迎来到天天文库
浏览记录
ID:55278825
大小:144.00 KB
页数:8页
时间:2020-05-08
《用java来实现Ntalk聊天工具.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、一、实验题目:Ntalk包括服务器,我以6个人聊天作为Ntalk开发的例子。二、程序清单1)服务器代码TCPServer.javaimportjava.io.*;importjava.net.*;publicclassTCPServer{//用数组来存放与客户机建立的5个socketpublicstaticSocket[]connectionSocket=newSocket[5];publicstaticvoidmain(String[]args)throwsException{//将服务器端口号设为6011finalintport=6011;//客户机的数量finalintn
2、=5;//输出服务器的ip地址信息以及客户机的数量InetAddressinet=InetAddress.getLocalHost();ServerSocketwelcomeSocket=newServerSocket(port);System.out.println("UNIX>Ntalk"+inet.getHostAddress()+""+(n+1)+''+"Server:Red_Hwan");for(inti=0;i3、务器当前已经有多少客户机已经建立连接了System.out.println("Client:Client"+(i+1)+"hasjoined");DataOutputStreamoutToClient=newDataOutputStream(TCPServer.connectionSocket[i].getOutputStream());outToClient.writeBytes("UNIX>Ntalk"+inet.getHostAddress()+'');outToClient.writeBytes("Server:Red_Hwan"+'');for(intj=0;4、j5、for(inti=0;i6、=0;i7、器上System.out.println("Red_Hwan:"+sentence);//将信息发送给所有的客户机for(intj=0;j
3、务器当前已经有多少客户机已经建立连接了System.out.println("Client:Client"+(i+1)+"hasjoined");DataOutputStreamoutToClient=newDataOutputStream(TCPServer.connectionSocket[i].getOutputStream());outToClient.writeBytes("UNIX>Ntalk"+inet.getHostAddress()+'');outToClient.writeBytes("Server:Red_Hwan"+'');for(intj=0;
4、j
5、for(inti=0;i6、=0;i7、器上System.out.println("Red_Hwan:"+sentence);//将信息发送给所有的客户机for(intj=0;j
6、=0;i7、器上System.out.println("Red_Hwan:"+sentence);//将信息发送给所有的客户机for(intj=0;j
7、器上System.out.println("Red_Hwan:"+sentence);//将信息发送给所有的客户机for(intj=0;j
此文档下载收益归作者所有