ImageVerifierCode 换一换
格式:DOCX , 页数:25 ,大小:52.54KB ,
资源ID:10015922      下载积分:3 金币
快捷下载
登录下载
邮箱/手机:
温馨提示:
快捷下载时,用户名和密码都是您填写的邮箱或者手机号,方便查询和重复下载(系统自动生成)。 如填写123,账号就是123,密码也是123。
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

加入VIP,免费下载
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.bdocx.com/down/10015922.html】到电脑端继续下载(重复下载不扣费)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

下载须知

1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。
2: 试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓。
3: 文件的所有权益归上传用户所有。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 本站仅提供交流平台,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

版权提示 | 免责声明

本文(网络编程技术设计说明书.docx)为本站会员(b****7)主动上传,冰豆网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知冰豆网(发送邮件至service@bdocx.com或直接QQ联系客服),我们立即给予删除!

网络编程技术设计说明书.docx

1、网络编程技术设计说明书网络编程技术大作业说明书题 目: 图形界面的一对多聊天软件课 程: 网络编程技术 院 (部): 计算机科学与技术专 业: 网络工程班 级: 学生姓名: 指导教师: 完成日期: 目 录图形界面的一对多的聊天软件的设计与实现 1一、问题描述 1二、小组成员及任务分配 1三、设计思想 1四、系统结构 1五、程序流程(或模块划分) 2六、源程序 8七、系统测试及操作界面 24结 论 27参考文献 28图形界面的一对多的聊天软件的设计与实现一、问题描述利用Socket技术,编程实现一个图形界面的一对多的聊天软件。需求如下:一、建立聊天室,显示进入聊天室和离开聊天室的客户信息。二、为

2、每一对进行聊天的客户单独开一个图形界面的聊天窗口。三、保存客户的聊天记录,并可以在聊天窗口中打开查询这些聊天记录。二、小组成员及任务分配本组所有成员在此次软件开发过程中的任务分配情况:三、设计思想系统需求分析:控制端,服务器,客户端,发送消息,聊天记录;首先启动后出现控制端界面;由控制端产生服务器与客户端;开始聊天;存放与读取聊天记录;结束聊天。系统设计:控制端:显示进入聊天室和离开聊天室的客户信息,生成一对聊天室;服务器与客户端功能:输入聊天消息,发送消息,显示聊天消息,查看消息记录,退出;四、系统结构控制端:在构造方法中设计界面、读取哈希表(存放用户对象,首次执行清空哈希表)、启动服务器(

3、阻塞于accept()方法,等待用户连接);在事件监听器中监听启动客户端。服务器与客户端:设计界面;两者之间通过数据输入输出流交互信息;存放与读取消息记录采用数据输入输出流与文件输入输出流来实现;退出时告之对方己方已退出聊天室并告之控制台,结束聊天有两种形式:一是点击退出按钮,二是发送“bye”消息。五、程序流程(或模块划分)程序流程图:控制端:判断用户是否已经加入聊天室if (table.containsKey(textf.getText() JOptionPane.showMessageDialog(null, 该客户端已经开启,请重新输入客户端名!); extf.setText();服务

4、器在构造方法中启动启动客户端方法new Thread(new Runnable() public void run() String str1=textf.getText(); client1 c1=new client1(); c1.test(str1);).start();主机接收 客户机 发来的消息,并将聊天记录存入文件fos=new FileOutputStream(src/chat/infoCache.txt,true);dos=new DataOutputStream(fos);din = new DataInputStream(socket.getInputStream(); w

5、hile (true) s2 = din.readUTF(); texta.append(clientName+ 说: + s2 + n); dos.writeUTF(clientName+ 说: + s2); if (s2.equalsIgnoreCase(bye) texta.append(断开连接 + n); chatRoom.texta.append(n+clientName+离开了聊天室,与+主机连接中断); din.close(); dout.close(); fos.close(); dos.close(); 主机向客户机发送消息,并将聊天记录存入文件fos=new FileOu

6、tputStream(src/chat/infoCache.txt,true);dos=new DataOutputStream(fos);texta.append(主机 说: + s1 + n);dos.writeUTF(主机 说: + s1);主机读取消息记录:fis=new FileInputStream(src/chat/infoCache.txt);dis=new DataInputStream(fis);String str=dis.readUTF();while(!str.equals() te.append(n+str); str=dis.readUTF();客户机接收 主机

7、发来的消息,并将聊天记录存入文件din = new DataInputStream(client.getInputStream();fos=new FileOutputStream(src/chat/+clientName+.txt,true);dos=new DataOutputStream(fos);while (true) s2 = din.readUTF(); texta1.append(主机 说: + s2 + n); dos.writeUTF(主机 说: + s2 ); f (s2.equalsIgnoreCase(bye) texta1.append(断开连接 + n); cha

8、tRoom.texta.append(n+主机离开了聊天室,与+clientName+连接中断); din.close(); dout.close(); 客户机向主机发送消息,并将聊天记录存入文件s1 = textf1.getText().trim();texta1.append(clientName+ 说: + s1 + n);try dout = new DataOutputStream(client.getOutputStream(); fos=new FileOutputStream(src/chat/+clientName+.txt,true); dos=new DataOutput

9、Stream(fos); dos.writeUTF(clientName+ 说: + s1); dout.writeUTF(s1); if (s1.equalsIgnoreCase(bye) texta1.append(断开连接 + n); din.close(); dout.close(); 客户机读取消息记录:fis=new FileInputStream(src/chat/+clientName+.txt);dis=new DataInputStream(fis);String str=dis.readUTF();while(!str.equals() te.append(n+str);

10、 str=dis.readUTF();六、源程序1、public class chatRoom extends JFrame implements ActionListener JFrame j; static ServerSocket server; DataInputStream din; DataOutputStream dout; String s1, s2, s3; JTextField textf; static JTextArea texta; JLabel label; JButton okbtn; JButton exbtn; JScrollPane scroll; Sock

11、et socket; String clientName=null; clientInfo client = null; Hashtable table = null; File file=new File(src/chat/clientInfo.txt); FileInputStream in1 = null; ObjectInputStream in2 = null; FileOutputStream out1 = null; ObjectOutputStream out2 = null; public chatRoom() /构造方法 j=new JFrame(聊天室); textf =

12、 new JTextField(20); label = new JLabel(输入客户端名); okbtn = new JButton(加入聊天室); exbtn = new JButton(退出); textf.addActionListener(this); okbtn.addActionListener(this); exbtn.addActionListener(this); JPanel jp1 = new JPanel(); jp1.add(label); jp1.add(textf); jp1.add(okbtn); jp1.add(exbtn); j.add(jp1, Bor

13、derLayout.SOUTH); texta = new JTextArea(12, 12); scroll = new JScrollPane(texta); j.add(scroll); j.setSize(600, 600); j.setVisible(true); j.setBackground(Color.blue); j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try /将哈希表从文件读出,并清空哈希表 in1 = new FileInputStream(file); in2 = new ObjectInputStream(

14、in1); table = (Hashtable) in2.readObject(); table.clear(); in1.close(); in2.close(); catch (Exception ee) ee.printStackTrace(); System.out.println(创建哈希表出现问题!); texta.append(服务器正在端口号5500监听客户端的连接请求); server server2=new server();/调用服务器的方法 server2.run(); public static void main(String args) / TODO Auto-

15、generated method stub chatRoom cr=new chatRoom(); public void actionPerformed(ActionEvent e) /监听动作事件,实现触发的动作事件 / TODO Auto-generated method stub if(e.getSource()=okbtn) client=new clientInfo(); if (textf.getText()!=null) if (table.containsKey(textf.getText() JOptionPane.showMessageDialog(null, 该客户端已

16、经开启,请重新输入客户端名!); textf.setText(); else /client.setStrName(textf.getText(); try out1 = new FileOutputStream(file); out2 = new ObjectOutputStream(out1); table.put(textf.getText(), client); out2.writeObject(table); out2.close(); out1.close(); catch (Exception ee) ee.printStackTrace(); new Thread(new Ru

17、nnable() public void run() String str1=textf.getText(); client1 c1=new client1(); c1.test(str1); ).start(); texta.append(n+textf.getText()+加入了聊天室); textf.setText(); if(e.getSource()=exbtn) System.exit(0); 2、public class server public void run()/ ServerSocket serSkt=null; Socket csSkt=null; chatServe

18、r server1; try serSkt=new ServerSocket(5500);/在端口号5500实例化一个对象 catch(IOException e) e.printStackTrace(); while(true) try System.out.println(服务器正在5500端口监听客户的连接请求); csSkt=serSkt.accept();/等待客户机的连接 server1=new chatServer(csSkt); new Thread(server1).start();/调用服务器类的run方法,接受客户机发送来消息 catch(IOException e) e

19、.printStackTrace(); 3、public class chatServer extends JFrame implements ActionListener,Runnable DataInputStream din; DataOutputStream dout; String s1, s2, s3; JTextField textf; JTextArea texta; JLabel label; JButton okbtn; JButton exbtn; JButton infoRecord; JScrollPane scroll; JFrame j1; Socket sock

20、et; String clientName=null; FileInputStream fis; FileOutputStream fos; DataInputStream dis; DataOutputStream dos; public chatServer(Socket s) throws IOException /构造方法 j1=new JFrame(主机); textf = new JTextField(20); label = new JLabel(发送消息); okbtn = new JButton(发送); infoRecord=new JButton(消息记录); exbtn

21、 = new JButton(退出); textf.addActionListener(this); okbtn.addActionListener(this); exbtn.addActionListener(this); infoRecord.addActionListener(this); JPanel jp2 = new JPanel(); jp2.add(label); jp2.add(textf); jp2.add(okbtn); jp2.add(infoRecord); jp2.add(exbtn); j1.add(jp2, BorderLayout.SOUTH); texta

22、= new JTextArea(12, 12); scroll = new JScrollPane(texta); j1.add(scroll); j1.setSize(600, 600); j1.setVisible(true); j1.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); socket=s; din=new DataInputStream(s.getInputStream(); dout=new DataOutputStream(s.getOutputStream(); clientName=din.readUTF(); Sy

23、stem.out.println(同+clientName+ +socket.getInetAddress().toString()+,+socket.getPort()+建立连接,开始聊天); public void run() /接收客户机发来的消息,并将聊天记录存入文件 try fos=new FileOutputStream(src/chat/infoCache.txt,true); dos=new DataOutputStream(fos); din = new DataInputStream(socket.getInputStream(); while (true) s2 = di

24、n.readUTF(); texta.append(clientName+ 说: + s2 + n); dos.writeUTF(clientName+ 说: + s2); if (s2.equalsIgnoreCase(bye) texta.append(断开连接 + n); chatRoom.texta.append(n+clientName+离开了聊天室,与+主机连接中断); din.close(); dout.close(); fos.close(); dos.close(); catch (IOException e) / TODO Auto-generated catch bloc

25、k System.out.println(链接已经断开!); public void exit() /断开连接 try dout.writeUTF(主机离开了聊天室); din.close(); dout.close(); dos.close(); fos.close(); chatRoom.texta.append(n+主机离开了聊天室,与+clientName+连接中断); catch (Exception e) /System.exit(0); public void actionPerformed(ActionEvent e) /动作事件监听器,实现触发的事件 / TODO Auto-

26、generated method stub if (e.getSource() = okbtn) s1 = textf.getText().trim(); try fos=new FileOutputStream(src/chat/infoCache.txt,true); dos=new DataOutputStream(fos); texta.append(主机 说: + s1 + n); dos.writeUTF(主机 说: + s1); catch (FileNotFoundException e2) / TODO Auto-generated catch block e2.printS

27、tackTrace(); catch(IOException e1) try dout = new DataOutputStream(socket.getOutputStream(); dout.writeUTF(s1); if (s1.equalsIgnoreCase(bye) texta.append(断开连接 + n); din.close(); dout.close(); catch (Exception e1) textf.setText(); textf.requestFocus(); if(e.getSource()=infoRecord) JDialog jd=new JDialog(); jd.setTitle(主机和客户机的消息记录); JTextArea te = new JTextArea(120, 120); JScrollPane roll = new JScrollPane(te); te.setEditable(false); jd.add(roll); jd.setSize(600, 600); jd.setVisible(true); jd.setBackground(Color.blue); jd.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); try fis=new FileInp

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1