求解一个java socket编程 自己写的socket通讯发现当client输入信息后Server端无法接受到信息,求指出问题地方。
Client 源码:import *;
import *;
public class ClientSocket {
public static void main(String [] args) throws Exception{
Socket accs=new Socket("127.0.0.1",8700);
BufferedReader mbr=new BufferedReader(new InputStreamReader(System.in));
PrintWriter tpw=new PrintWriter(accs.getOutputStream());
BufferedReader fmbrs=new BufferedReader(new InputStreamReader(accs.getInputStream()));
String strMessage = mbr.readLine();
while(!strMessage.equals("exit")){
tpw.print(strMessage);
tpw.flush();
System.out.println("Send to server: "+ strMessage);
System.out.println("Serve say : "+ fmbrs.readLine());
strMessage = mbr.readLine();
}
tpw.close();
fmbrs.close();
accs.close();
}
}
Server端源码:
import *;
import *;
public class HostSocket {
public static void main(String [] args) throws Exception{
ServerSocket mss=new ServerSocket(8700);
Socket accs= mss.accept();
String strInMessage;
BufferedReader mbrc=new BufferedReader(new InputStreamReader(accs.getInputStream()));
PrintWriter mpw=new PrintWriter(accs.getOutputStream());
BufferedReader mbr=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Client Say: "+mbrc.readLine());
strInMessage=mbr.readLine();
while(!strInMessage.equals("exit")){
mpw.print(strInMessage);
mpw.flush();
System.out.println("Send to Client Message: "+strInMessage);
System.out.println("Client say "+mbrc.readLine());
strInMessage=mbr.readLine();
}
mpw.close();
mbrc.close();
accs.close();
mss.close();
}
}