import java.util.*;
import java.io.*;
import java.net.*;
public class TestServer2 {
public static void main(String [] args) {
try {
ServerSocket ss;
ss = new ServerSocket(8888);
}catch(IOException e) {
System.out.println("传输错误");
}
Socket s = new Socket();
try{
s = ss.accept();
}catch(Exception e) {
System.out.println("连接失败");
}
try {
BufferedWriter bo = new BufferedWriter( new OutputStreamWriter(s.getOutputStream()));
BufferedReader bi = new BufferedReader(new InputStreamReader(s.getInputStream()));
}catch(IOException e) {
e.printStackTrace();
}
try {
String str = null;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
str = br.readLine();
while(!str.equals("bye")) {
bo.write(str);
System.out.println("Cilent : " + bi.readLine());
str = br.readLine();
}
bo.close();
bi.close();
br.close();
}catch(IOException e) {
e.printStackTrace();
}
}
}
```![图片说明](https://img-ask.csdn.net/upload/201606/02/1464833487_755523.png)