博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
J2E——网络编程练习
阅读量:6602 次
发布时间:2019-06-24

本文共 2298 字,大约阅读时间需要 7 分钟。

hot3.png

    Server端程序:

/** * @description 根据条件查询 * @author libingbin2015@aliyun.com * @date */package test.demo;import java.net.*;import java.io.*; public class Server {    private ServerSocket ss;    private Socket socket;    private BufferedReader in;    private PrintWriter out;    public Server() {         try  {            ss=new ServerSocket(10000);            while(true) {                socket = ss.accept();                String RemoteIP = socket.getInetAddress().getHostAddress();                String RemotePort = ":"+socket.getLocalPort();                System.out.println("A client come in!IP:"+RemoteIP+RemotePort);                in = new BufferedReader(new InputStreamReader(socket.getInputStream()));                String line = in.readLine();                System.out.println("Cleint send is :" + line);                out = new PrintWriter(socket.getOutputStream(),true);                out.println("Your Message Received!");                out.close();                in.close();                socket.close();            }        }catch (IOException e)  {            out.println("wrong");        }    }    public static void main(String[] args) {        new Server();    }};

 

    Client端程序:

/** * @description 根据条件查询 * @author libingbin2015@aliyun.com * @date */package test.demo;import java.io.*;import java.net.*; public class Client {   private Socket socket;   private BufferedReader in;   private PrintWriter out;    public Client() {    try {            System.out.println("Try to Connect to 127.0.0.1:10000");            socket = new Socket("127.0.0.1",10000);            System.out.println("The Server Connected!");            System.out.println("Please enter some Character:");            BufferedReader line = new BufferedReader(new InputStreamReader(System.in));            out = new PrintWriter(socket.getOutputStream(),true);            out.println(line.readLine());            in = new BufferedReader(new InputStreamReader(socket.getInputStream()));            System.out.println(in.readLine());            out.close();            in.close();            socket.close();        }catch(IOException e) {            out.println("Wrong");        }    }        public static void main(String[] args) {        new Client();    }};

 

转载于:https://my.oschina.net/u/3375733/blog/1499189

你可能感兴趣的文章
Python dict dictionaries Python 数据结构——字典
查看>>
【SICP练习】151 练习4.7
查看>>
MySQL高可用架构之Keepalived+主从架构部署
查看>>
如何在分组时,连接多个行数据
查看>>
Codeforces 1149 B - Three Religions
查看>>
js中的scrollTop、offsetTop、clientTop
查看>>
11-border(边框)
查看>>
4.字符串(2-6/2-7)
查看>>
bugfree3.0.1-邮件配置
查看>>
ASP.Net MVC View(视图)
查看>>
有关git clone 下载速度变慢的解决方法
查看>>
Papervision3D Essentials中文版,附Papervision3D_2.1.920.swc和章节练习源码
查看>>
Mysql汉字乱码的解决
查看>>
FMDB增删改查小Demo
查看>>
UNIX网络编程卷2 源码编译篇
查看>>
(一)认识Sass和Compass
查看>>
哈尔滨理工大学第七届程序设计竞赛决赛(网络赛-高年级组)C - 小明打联盟...
查看>>
POJ 1930 Dead Fraction
查看>>
PAT (Advanced Level) 1028. List Sorting (25)
查看>>
获取oracle数据库对象定义
查看>>