Socket 编程基础 - 航班显示系统客户端
更新时间:2023-10-21 17:50:01 阅读量: 综合文库 文档下载
- socket推荐度:
- 相关推荐
《网络编程技术》实验报告
实验三 Socket 编程基础——航班显示系统客户端的设计与实现
一. 实验目的
1、 理解基于 TCP 的网络连接、套接字的基本概念 2、 熟悉并熟练掌握 Java 中 Socket 类的使用
3、 熟练掌握基于 TCP 的网络客户端的数据读写操作和客户端软件设计
二. 实验环境
1、 准备 SUN 的 JDK6 安装文件
2、 Java 程序开发软件一套——MyEclipse
三. 实验实际完成内容及结果分析(请先说明你在小组中所承担的任务)
import java.awt.EventQueue;
import javax.swing.JFrame; import javax.swing.JPanel;
import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; import javax.swing.JTable; import javax.swing.JButton; import javax.swing.JScrollPane;
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.Socket;
import java.net.UnknownHostException; import java.io.FileReader; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.Enumeration; import java.util.LinkedList; import java.util.Hashtable; import java.util.regex.Matcher; import java.util.regex.Pattern; import java.awt.BorderLayout; import java.awt.GridBagLayout;
《网络编程技术》实验报告
import java.awt.GridBagConstraints; import java.awt.Insets;
public class FlyFrame1 extends JFrame {
/**
* Create the frame. *
* @throws IOException */
public FlyFrame1() throws IOException {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 800, 400); contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); setContentPane(contentPane); /**
* Launch the application. */
public static void main(String[] args) { }
EventQueue.invokeLater(new Runnable() { });
public void run() { }
try { }
FlyFrame1 frame = new FlyFrame1(); frame.setVisible(true); e.printStackTrace();
private JPanel contentPane; private JTable flyTable;
private static LinkedList 数据列表(读入线程和处理线程共享资源) 据列表(处理线程和显示线程共享资源) // 城市代码 Integer>(); // 基于flid的表索引 } catch (Exception e) { 《网络编程技术》实验报告 0); // 连接按钮动作 // 创建连接按钮 JButton connectButton = new JButton(\); GridBagConstraints gbc_connectButton = new GridBagConstraints(); gbc_connectButton.insets = new Insets(3, 0, 0, 0); gbc_connectButton.ipadx = 50; gbc_connectButton.fill = GridBagConstraints.VERTICAL; gbc_connectButton.gridx = 0; gbc_connectButton.gridy = 0; buttonPanel.add(connectButton, gbc_connectButton); JPanel buttonPanel = new JPanel(); contentPane.add(buttonPanel, BorderLayout.SOUTH); GridBagLayout gbl_buttonPanel = new GridBagLayout(); gbl_buttonPanel.columnWidths = new int[] { 772, 0 }; gbl_buttonPanel.rowHeights = new int[] { 27, 0 }; gbl_buttonPanel.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; gbl_buttonPanel.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; buttonPanel.setLayout(gbl_buttonPanel); flyTable = new JTable(flyTableModel); flyTableScrollPane.setViewportView(flyTable); // 创建表 final DefaultTableModel flyTableModel = new DefaultTableModel( new String[] { \航班号\, \前往\, \办票时间\, \预计起飞时间\, \登机口\ }, // 创建滚动条 JScrollPane flyTableScrollPane = new JScrollPane(); contentPane.add(flyTableScrollPane, BorderLayout.CENTER); // 创建城市代码映射表 BufferedReader cityReader = new BufferedReader(new FileReader( \)); String cityString = null; while ((cityString = cityReader.readLine()) != null) { } cityReader.close(); contentPane.setLayout(new BorderLayout(0, 0)); String[] aircodeArray = cityString.split(\); // citycode.put(aircodeArray[0], aircodeArray[2]); citycode.put(aircodeArray[0], aircodeArray[1]); 《网络编程技术》实验报告 connectButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // 完成耗时的动作时必须开新线程,否则会导致更新出错 // 读入线程 new Thread() { @Override public void run() { // TODO 自动生成的方法存根 try { // 创建socket Socket socket = new Socket(\, 9999); // 读入数据 try { } BufferedReader flyReader = new BufferedReader( new InputStreamReader(socket .getInputStream())); String processString = null; while ((processString = flyReader.readLine()) != \ if (processString // 共享资源processList同步块 synchronized (processList) { processList.addLast(processString); processList.notify(); data!\) { .matches(\)) { }// end synchronized }// end if }// end while stopflog = true; flyReader.close(); // 关闭流 // TODO 自动生成的 catch 块 e.printStackTrace(); try { } if (socket != null) socket.close(); } catch (IOException e) { } finally { } catch (IOException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (UnknownHostException e) { 《网络编程技术》实验报告 // 更新数据 if (tableindex.get(matcherFild.group(1)) != null) { // 获取索引 index = tableindex.get(matcherFild.group(1)); // 设置对应flid的数据是否存在标记,默认值为-1 Integer index = -1; // 记录航班ID Matcher matcherFild = Pattern.compile( \) /* 匹配并捕获flid */ .matcher(processString); matcherFild.find(); String processString = null; // 共享资源processList同步块 synchronized (processList) { } while (processList.isEmpty()) { // 如果处理数据 } processString = processList.removeFirst(); // processList.wait(); // 处理线程 new Thread() { public void run() { while (true) { try { // 处理结束 if (stopflog && processList.isEmpty()) { } break; } // TODO 自动生成的 catch 块 e.printStackTrace(); // TODO 自动生成的 catch 块 e.printStackTrace(); } catch (IOException e) { };// end run }.start();// end thread 列表中没有数据,则进入休眠状态 取出处理数据列表的第一项
正在阅读:
客服服务准则11-09
六年级数学上册计算天天练8811-28
青海我美丽的家乡作文800字07-16
网络经济学名词解释10-05
关于农村征地和城市拆迁课题研究03-15
未来的住宅作文600字07-09
城管中队关于开展作风建设自查自纠的报告04-08
年产100吨2申请备案情况说明09-10
管理沟通结课作业12-30
- 多层物业服务方案
- (审判实务)习惯法与少数民族地区民间纠纷解决问题(孙 潋)
- 人教版新课标六年级下册语文全册教案
- 词语打卡
- photoshop实习报告
- 钢结构设计原理综合测试2
- 2014年期末练习题
- 高中数学中的逆向思维解题方法探讨
- 名师原创 全国通用2014-2015学年高二寒假作业 政治(一)Word版
- 北航《建筑结构检测鉴定与加固》在线作业三
- XX县卫生监督所工程建设项目可行性研究报告
- 小学四年级观察作文经典评语
- 浅谈110KV变电站电气一次设计-程泉焱(1)
- 安全员考试题库
- 国家电网公司变电运维管理规定(试行)
- 义务教育课程标准稿征求意见提纲
- 教学秘书面试技巧
- 钢结构工程施工组织设计
- 水利工程概论论文
- 09届九年级数学第四次模拟试卷
- 显示系统
- 航班
- 客户端
- 编程
- 基础
- Socket
- 小学语文简单实用的阅读答题技巧(附训练题及答案)
- 《平凡世界》前六章测试题
- 刚体力学
- 基于C语言的五子棋程序毕业课程设计报告
- 信号分析与处理14~15上期末试卷A答案
- 第65届联合国大会中国立场文件 中英对照版
- 预应力锚索施工技术交底(1)
- 标准化概论练习题(2017)
- 吴家河隧道右线K32+685~K32+691段洞口变更
- 福建三基护理(电子版)
- 1104报表填报说明(2016年版) - 图文
- 2014Revit工程师题库
- 鄂建文152号:关于进一步加强建筑工程质量管理的通知
- 北大15年春《大学英语3》作业三答案
- 苏少版 - 八年级上册美术试题分析
- 广东省中山一中2011-2012学年高一下学期第一次段考化学试题
- 毛概调查报告作业 - 图文
- 浅谈培养小学生的符号意识
- 宽容作文之有关教师宽容学生的作文
- 吉林省东北师大附中2015-2016学年高中数学 第一章 常用逻辑用语 1.1-1 命题教案