客户端录入
package cn.itcast_01;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
public class ClientDome {
public static void main(String[] args) throws IOException, IOException {
Socket s = new Socket("10.216.3.155",33433);
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(
s.getOutputStream()));
String line = null;
while((line = br.readLine()) != null ) {
if("886".equals(line)) {
break;
}
bw.write(line);
bw.newLine();
bw.flush();
}
s.close();
}
}
服务器
package cn.itcast_01;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;
public class Server {
public static void main(String[] args) throws IOException {
ServerSocket ss = new ServerSocket(33433);
Socket s = ss.accept();
BufferedReader br= new BufferedReader(new InputStreamReader(
s.getInputStream()));
String line = null;
while((line = br.readLine()) != null){
System.out.println(line);
}
s.close();
}
}