A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

import java.net.*;

import java.io.*;

public class TestServer { //服务器端

public static void main(String[] args) {

try{

ServerSocket ss = new ServerSocket(9999);  

Socket s = ss.accept();  

BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));

BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Client:" + br.readLine());

String str2 = br1.readLine();

while(!str2.equalsIgnoreCase("bye")){

bw.write(str2+"\n");

bw.flush();

//System.out.println("Server:" + str2);  

System.out.println("Client:" + br.readLine());

str2 = br1.readLine();

}

br.close();

br1.close();

bw.close();

s.close();

ss.close();

}catch(IOException e){

e.printStackTrace();}

}

}


import java.net.*;

import java.io.*;

public class TestClient{ //客服端

public static void main(String[] args) {

try{

Socket s = new Socket("127.0.0.1",9999);

BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));

BufferedWriter bw= new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

BufferedReader br1 = new BufferedReader(new InputStreamReader(System.in));

String str = br1.readLine();   

while(!str.equalsIgnoreCase("bye")){

bw.write(str+"\n");

bw.flush();

//System.out.println("Client:" + str);

System.out.println("Server:" + br.readLine());  

str = br1.readLine();

}

br.close();

br1.close();

bw.close();

s.close();

}catch(IOException e){

e.printStackTrace();

}

}

}

2 个回复

倒序浏览
哥们,你这基本没一句注释啊
回复 使用道具 举报
神之梦 发表于 2013-8-16 14:15
哥们,你这基本没一句注释啊

呃,忘加了
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马