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

加入VIP,免费下载
 

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

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

下载须知

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

版权提示 | 免责声明

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

JAVA开发进阶实验报告模板.docx

1、JAVA开发进阶实验报告模板java开发进阶实验报告实验序号:4 实验项目名称:套接字通信学号姓名何征专业、班12软件工程实验地点实1-518指导教师唐朝辉实验时间2013.3.26一、实验目的及要求了解套接字通信并且熟悉输入流、输出流得操作同时掌握套接字编程二、实验设备(环境)及要求windows 操作系统;Eclipse PC计算机三、实验内容与步骤1. 请看例子4-2。2. 请看例子4-4。四、实验结果与数据处理五、分析与讨论编写的过程当中,客户端和服务端经常出现系统崩溃,后来才发现是编写的代码出现了问题,导致使用不了,后来在努力查找下终于实现了运行。第二个实验也是,比较多的问题都是代码

2、出错,表示写得有点纠结,不过之后经过修改就成功了。发现细心很重要。六、教师评语签名:日期:成绩列出程序代码:一(1)、import java.io.*;import .*;import .Socket;public class ServerThread extends Thread private Socket connectToClient; private DataInputStream inFromClient; private DataOutputStream outToClient; public ServerThread(Socket socket) throws IOExcept

3、ion super(); connectToClient=socket; inFromClient=new DataInputStream(connectToClient.getInputStream(); outToClient=new DataOutputStream(connectToClient.getOutputStream(); start(); public void run() try String str; double radius,area; boolean goon=true; while(goon) str=inFromClient.readUTF(); if(!st

4、r.equals(bye) radius=Double.parseDouble(str); System.out.println(接收到得半径值为:+radius); area=radius*radius*Math.PI; str=Double.toString(area); outToClient.writeUTF(str); outToClient.flush(); System.out.println(圆面积+str+已经发送); else goon=false; outToClient.writeUTF(bye); outToClient.flush(); inFromClient.c

5、lose(); outToClient.close(); connectToClient.close(); catch(IOException e) e.printStackTrace(); (2)import java.io.*;import .*;public class MultiServer public static void main(String args) try System.out.println(等待连接); ServerSocket serverSocket=new ServerSocket(3500); Socket connectToClient=null; whi

6、le(true) connectToClient=serverSocket.accept(); new ServerThread(connectToClient); catch(IOException e) e.printStackTrace(); (3)import java.io.*;import .*;import .Socket;public class Client public static void main(String args) try Socket connectToServer=new Socket(localhost,200); DataInputStream inF

7、romServer=new DataInputStream(connectToServer.getInputStream(); DataOutputStream outToServer=new DataOutputStream(connectToServer.getOutputStream(); String outStr,inStr; boolean goon=true; BufferedReader buf=new BufferedReader(new InputStreamReader(System.in); while(goon) outStr=buf.readLine(); outT

8、oServer.writeUTF(outStr); outToServer.flush(); inStr=inFromServer.readUTF(); if(!inStr.equals(bye) System.out.println(从服务器返回的结果是+inStr); else goon=false; inFromServer.close(); outToServer.close(); connectToServer.close(); catch(IOException e) e.printStackTrace(); (3)import java.io.*;import .*;import

9、 .Socket;public class Client public static void main(String args) try Socket connectToServer=new Socket(localhost,); DataInputStream inFromServer=new DataInputStream(connectToServer.getInputStream(); DataOutputStream outToServer=new DataOutputStream(connectToServer.getOutputStream(); System.out.prin

10、tln(输入半径数值发送到服务器,输入bye结束。); String outStr,inStr; boolean goon=true; BufferedReader buf=new BufferedReader(new InputStreamReader(System.in); while(goon) outStr=buf.readLine(); outToServer.writeUTF(outStr); outToServer.flush(); inStr=inFromServer.readUTF(); if(!inStr.equals(bye) System.out.println(从服务

11、器返回的结果是+inStr); else goon=false; inFromServer.close(); outToServer.close(); connectToServer.close(); catch(IOException e) e.printStackTrace(); 二(1)、import java.io.*;import .*;import java.awt.*;import java.awt.Container;import java.awt.FlowLayout;import java.awt.event.*;import javax.swing.*;public cl

12、ass chatServer implements ActionListener,Runnable JTextArea showArea; JTextField msgText; JFrame mainJframe; JButton sentBtn; JScrollPane JSPane; JPanel pane; Container con; Thread thread=null; ServerSocket serverSocket; Socket connectToClient; DataInputStream inFromClient; DataOutputStream outToCli

13、ent; public chatServer() mainJframe=new JFrame(聊天服务器端); con=mainJframe.getContentPane(); showArea=new JTextArea(); showArea.setEditable(false); showArea.setLineWrap(true); JSPane=new JScrollPane(showArea); msgText.setColumns(30); msgText.addActionListener(this); sentBtn=new JButton(发送); sentBtn.addA

14、ctionListener(this); pane=new JPanel(); pane.setLayout(new FlowLayout(); pane.add(msgText); pane.add(sentBtn); con.add(JSPane,BorderLayout.CENTER); con.add(pane,BorderLayout.SOUTH); mainJframe.setSize(500,400); mainJframe.setVisible(true); mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); t

15、ry serverSocket=new ServerSocket(5500); showArea.append(正在等待对话请求n); connectToClient=serverSocket.accept(); inFromClient=new DataInputStream(connectToClient.getInputStream(); outToClient=new DataOutputStream(connectToClient.getOutputStream(); thread=new Thread(this); thread.setPriority(Thread.MIN_PRI

16、ORITY); thread.start(); catch(IOException e) showArea.append(对不起,不能创建服务器n); msgText.setEditable(false); sentBtn.setEnabled(false); public static void main(String args) new chatServer(); public void actionPerformed(ActionEvent e) String s=msgText.getText(); if(s.length()0) try outToClient.writeUTF(s)

17、; outToClient.flush(); showArea.append(我说:+msgText.getText()+n); catch(IOException e1) showArea.append(你的消息:”+msgText.getText()+“未能发送出去n); public void run() try while(true) showArea.append(对方说:+inFromClient.readUTF()+n); Thread.sleep(1000); catch(IOException el) catch(InterruptedException e) 实验二impo

18、rt java.awt.*;import java.awt.event.*;import java.io.*;import .*;import javax.swing.*;public class chatClient implements ActionListener,Runnable JTextArea showArea; JTextField msgText; JFrame mainJframe; JButton sentBtn; JScrollPane JSPane; JPanel pane; Container con; Thread thread=null; Socket conn

19、ectToServer; DataInputStream inFromServer; DataOutputStream outToServer; public chatClient() mainJframe=new JFrame(聊天-客户端); con=mainJframe.getContentPane(); showArea=new JTextArea(); showArea.setEditable(false); showArea.setLineWrap(true); JSPane=new JScrollPane(showArea); msgText=new JTextField();

20、msgText.setColumns(30); msgText.addActionListener(this); sentBtn=new JButton(发送); sentBtn.addActionListener(this); pane=new JPanel(); pane.setLayout(new FlowLayout(); pane.add(msgText); pane.add(sentBtn); con.add(JSPane, BorderLayout.CENTER); con.add(pane, BorderLayout.SOUTH); mainJframe.setSize(500

21、,400); mainJframe.setVisible(true); mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try connectToServer=new Socket(localhost,5500); inFromServer=new DataInputStream( connectToServer.getInputStream(); outToServer=new DataOutputStream( connectToServer.getOutputStream(); showArea.append(连接成功

22、,请说话n); thread=new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); catch(IOException e) showArea.append(对不起,没能连接到服务器n); msgText.setEditable(false); sentBtn.setEnabled(false); public static void main(String args) new chatClient(); public void actionPerformed(ActionEvent e) Stri

23、ng s=msgText.getText(); if(s.length()0) try outToServer.writeUTF(s); outToServer.flush(); showArea.append(我说:+msgText.getText()+n); msgText.setText(null); catch(IOException el) showArea.append(你的消息:+msgText.getText()+未能发送出去n); public void run() try while(true) showArea.append(对方说:+inFromServer.readU

24、TF()+n); Thread.sleep(1000); catch(IOException el) catch(InterruptedException e) 服务端:import java.awt.*;import java.awt.event.*;import java.io.*;import .*;import javax.swing.*;public class chatServer implements ActionListener,Runnable JTextArea showArea; JTextField msgText; JFrame mainJframe; JButton

25、 sentBtn; JScrollPane JSPane; JPanel pane; Container con; Thread thread=null; ServerSocket serverSocket; Socket connectToClient; DataInputStream inFromClient; DataOutputStream outToClient; public chatServer() mainJframe=new JFrame(聊天-服务器端); con=mainJframe.getContentPane(); showArea=new JTextArea();

26、showArea.setEditable(false); showArea.setLineWrap(true); JSPane=new JScrollPane(showArea); msgText=new JTextField(); msgText.setColumns(30); msgText.addActionListener(this); sentBtn=new JButton(发送); sentBtn.addActionListener(this); pane=new JPanel(); pane.setLayout(new FlowLayout(); pane.add(msgText

27、); pane.add(sentBtn); con.add(JSPane, BorderLayout.CENTER); con.add(pane, BorderLayout.SOUTH); mainJframe.setSize(500,400); mainJframe.setVisible(true); mainJframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); try serverSocket=new ServerSocket(5500); showArea.append(正在等待对话请求n); connectToClient=ser

28、verSocket.accept(); inFromClient=new DataInputStream( connectToClient.getInputStream(); outToClient=new DataOutputStream( connectToClient.getOutputStream(); thread=new Thread(this); thread.setPriority(Thread.MIN_PRIORITY); thread.start(); catch(IOException e) showArea.append(对不起,不能创建服务器); msgText.setEditable(false); sentBtn.setEnabled(false);

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

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