大家帮忙一下,为什么下面两个程序间不能传送字符串
服务器端
import java.io.*;
import java.net.*;
public class socketserverTest
{
public static void main(String args[])
{
send();
}
public static void send()
{
try{
ServerSocket sersocket=new ServerSocket(4567);
Socket socket=sersocket.accept();
System.out.println("link");
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter pr=new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
String str=br.readLine();
System.out.println(str);
pr.write("recvice");
br.close();
pr.close();
sersocket.close();
}
catch(IOException ioe){System.err.println(ioe);}
}
}
下面是客户端
import java.io.*;
import java.net.*;
public class socketTest
{
public static void main(String args[])
{
send();
}
public static void send()
{
try{
Socket socket=new Socket(InetAddress.getLocalHost(),4567);
BufferedReader br=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter wt=new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
System.out.println("send");
wt.print("send");
System.out.println(br.readLine());
br.close();
wt.close();
socket.close();
}
catch(UnknownHostException hoste){System.err.println(hoste);}
catch(IOException ioe){System.err.println(ioe);}
finally
{ }
}
}