socket问题??

03-11-12 tesge
下面这端程序,想实现服务端输出从client端收到的消息,client端收到server端发出的消息。但运行后无信息输出,当把DataOutputStream改成PrintStream后即可输出,为什么?

client:

try

{

Socket socket = new Socket("172.30.93.81",8081);

DataInputStream input = new DataInputStream(new BufferedInputStream (socket.getInputStream()));

//PrintStream output =new PrintStream(socket.getOutputStream());

DataOutputStream output =new DataOutputStream(socket.getOutputStream());

//output.println("send from client");

output.writeBytes("send from client");

String value = "";

while((value =input.readLine()) !=null)

{

System.out.println(" accept : " + value);

}

input.close();

output.close();

socket.close();

}

server端:

ServerSocket server =new ServerSocket(8081);

Socket socket = server.accept();

DataOutputStream output =new DataOutputStream(socket.getOutputStream());

//PrintStream output =new PrintStream(socket.getOutputStream());

DataInputStream input = new DataInputStream(new BufferedInputStream (socket.getInputStream()));

output.writeBytes("come from server-");

//output.println("come from server-");

String value="";

while((value =input.readLine()) !=null)

{

System.out.println(" accept : " + value);

}

input.close();

output.close();

socket.close();

猜你喜欢