import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
import java.net.UnknownHostException;
public class Client1 {
public static void main(String[] args) {
try {
Socket soc = new Socket("127.0.0.1",55555);
//接收服务端的提示
InputStream in = soc.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = reader.readLine();
System.out.println("服务端说:"+line);
//告诉服务端我的身份
OutputStream output = soc.getOutputStream();
PrintStream ps = new PrintStream(output);
ps.println(" I am wenzhui ");
//获取键盘输入
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("很高兴为你服务, 请说出你想说的话:");
boolean flag = false;
//随时向服务端发送数据
while( !flag ){
System.out.println("服务端说你说的是:"+line);
ps.println(br.readLine());
ps.flush();
line = reader.readLine();
}
in.close();
reader.close();
output.close();
ps.close();
soc.close();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}