java实现客户端与服务端之间的通信
输入IP与端口号即可实现客户端与服务端之间的通信
import http://doc.guandang.net.*;
import java.io.*;
import java.util.Calendar;
import java.awt.*;
import java.awt.event.*;
class EchoClient extends Frame implements ActionListener,Runnable{
Thread t; static Calendar T; static int H; static int M;
static int S;
static String l;
private Button b1 = new Button("发送");
private Button b2 = new Button("关闭");
private TextField t1 = new TextField(30); private TextArea t2 = new TextArea(); private int m; private String n; Socket connection; DataInputStream in; DataOutputStream out; private class window extends WindowAdapter{ public void windowClosing(WindowEvent e){ System.exit(0); }
}
private void focusEvt(java.awt.event.WindowEvent evt) {
t1.requestFocus(); }
public void clock(){
T=Calendar.getInstance();
}
public EchoClient(String i,int j){
super("客户端");
} t = new Thread(this); m=j; n=i; t.start(); H=T.get(Calendar.HOUR_OF_DAY); M=T.get(Calendar.MINUTE); S=T.get(Calendar.SECOND); l=String.valueOf(H)+":"+String.valueOf(M)+":"+String.valueOf(S);
输入IP与端口号即可实现客户端与服务端之间的通信
public void run(){
Panel p1 = new Panel();
p1.setLayout(new FlowLayout());
p1.add(b2);p1.add(t1);p1.add(b1);
setLayout(new BorderLayout()); add("South",p1);add("Center",t2); b1.addActionListener(this); b2.addActionListener(this); t1.addActionListener(this); addWindowListener(new window()); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { focusEvt(evt); } });
setSize(400,300);
setVisible(true);
try{
connection = new Socket(n,m);
in = new DataInputStream(connection.getInputStream());
out = new DataOutputStream(connection.getOutputStream()); String link = new String("");
while(!link.toUpperCase().equals(".QUIT")){
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==b1||e.getSource()==t1){ String line = t1.getText(); clock(); t2.append("客户端 "+l+"\n"+line+"\n\n"); t1.setText(""); link = in.readUTF(); clock(); t2.append("服务端 "+l+"\n"+link+"\n\n");} }catch(UnknownHostException uhe){ System.err.println("Unknown Host:127.0.0.1"); } catch(IOException ioe){ } System.err.println("IOException:"+ioe);
输入IP与端口号即可实现客户端与服务端之间的通信
try{
} } public static String readString(){ String string = new String(); BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); try{ string = in.readLine(); } catch(IOException e){ System.out.println("Console.readString:Unknown error..."); System.exit(-1); } return string; } } else if(e.getSource()==b2){ } System.exit(0); out.writeUTF(line); }catch(IOException ioe){ System.err.println("IOException:"+ioe);
}
class stat extends Frame implements ActionListener{
private Label l1 = new Label("请输入IP地址:");
private Label l2 = new Label("端口号:");
private TextField q1 = new TextField(10);
private TextField q2 = new TextField(10);
private Button r1 = new Button("确定");
private Button r2 = new Button("关闭");
private int j;
private String i,k;
private class window extends WindowAdapter{
} private void focusEvt(java.awt.event.WindowEvent evt) { q1.requestFocus(); } public void windowClosing(WindowEvent e){ System.exit(0); }
输入IP与端口号即可实现客户端与服务端之间的通信
public stat(){
Panel y = new Panel(); y.setLayout(new GridLayout(4,1)); y.add(l1);y.add(q1);y.add(l2);y.add(q2); Panel x = new Panel(); x.setLayout(new FlowLayout()); x.add(r2);x.add(r1); setLayout(new BorderLayout()); add("South",x);add("Center",y); r1.addActionListener(this); r2.addActionListener(this); q1.addActionListener(this); q2.addActionListener(this); addWindowListener(new java.awt.event.WindowAdapter() { public void windowOpened(java.awt.event.WindowEvent evt) { focusEvt(evt); } }); addWindowListener(new window()); setSize(200,150);
setVisible(true);
}
public void actionPerformed(ActionEvent e){
if(e.getSource()==q1){
} q2.requestFocus();
else if(e.getSource()==r1||e.getSource()==q2){
i=q1.getText();
k=q2.getText();
j=Integer.parseInt(k);
new EchoClient(i,j);
dispose();
}
else if(e.getSource()==r2){ System.exit(0); }
}
public static void main(String args[]){
}
}
stat a = new stat();
输入IP与端口号即可实现客户端与服务端之间的通信
import http://doc.guandang.net.*;
import java.io.*;
import java.util.Calendar;
import java.awt.*;
import java.awt.event.*;
class EchoServer{
}
class EchoServer1 extends Frame implements ActionListener,Runnable{
Thread t; static Calendar T; static int H; static int M; static int S; static String l; private static boolean running = true; public static void main(String args[]){ try{ } ServerSocket server = new ServerSocket(7777); while(running){ Socket connection = server.accept(); } EchoServer1 handler = new EchoServer1(connection); }catch(IOException ioe){ System.err.println("IOException:"+ioe); …… 此处隐藏:4525字,全部文档内容请下载后查看。喜欢就下载吧 ……
相关推荐:
- [外语考试]管理学 第13章 沟通
- [外语考试]07、中高端客户销售流程--分类、筛选讲
- [外语考试]2015-2020年中国高筋饺子粉市场发展现
- [外语考试]“十三五”重点项目-汽车燃油表生产建
- [外语考试]雅培奶粉培乐系列适用年龄及特点
- [外语考试]九三学社入社申请人调查问卷
- [外语考试]等级薪酬体系职等职级表
- [外语考试]货物买卖合同纠纷起诉状(范本一)
- [外语考试]青海省实施消防法办法
- [外语考试]公交车语音自动报站系统的设计第3稿11
- [外语考试]logistic回归模型在ROC分析中的应用
- [外语考试]2017-2021年中国隔膜泵行业发展研究与
- [外语考试]神经内科下半年专科考试及答案
- [外语考试]园林景观设计规范标准
- [外语考试]2018八年级语文下册第一单元4合欢树习
- [外语考试]分布式发电及微网运行控制技术应用
- [外语考试]三人行历史学笔记:中世纪人文主义思想
- [外语考试]2010届高考复习5年高考3年联考精品历史
- [外语考试]挖掘机驾驶员安全生产责任书
- [外语考试]某211高校MBA硕士毕业论文开题报告(范
- 用三层交换机实现大中型企业VLAN方案
- 斯格配套系种猪饲养管理
- 涂层测厚仪厂家直销
- 研究生学校排行榜
- 鄱阳湖湿地景观格局变化及其驱动力分析
- 医学基础知识试题库
- 2010山西省高考历年语文试卷精选考试技
- 脉冲宽度法测量电容
- 谈高职院校ESP教师的角色调整问题
- 低压配电网电力线载波通信相关技术研究
- 余额宝和城市商业银行的转型研究
- 篮球行进间运球教案
- 气候突变的定义和检测方法
- 财经大学基坑开挖应急预案
- 高大支模架培训演示
- 一种改进的稳健自适应波束形成算法
- 2-3-鼎视通核心人员薪酬股权激励管理手
- 我国电阻焊设备和工艺的应用现状与发展
- MTK手机基本功能覆盖测试案例
- 七年级地理教学课件上册第四章第一节




