一个简单客户端和服务器端,中间流的读取一直出问题。。。。各位gg,jj帮忙看看啊
大二实习,给布置的任务,还要求要能实现中文的输入,输出,但是出现问题,程序到了发出后就没动了,不知道错到哪里了,555.
客户端
public class Client {
public static void main(String[] args) throws
IOException {
String send=null;
System.out.println("请输入");
Scanner getSend=new Scanner(System.in);
send=getSend.next();
Socket s =new Socket("127.0.0.1",4242);
System.out.println("Connected to server...sending echo string");
PrintWriter writer =new PrintWriter(s.getOutputStream());
writer.println(send);
writer.flush();
InputStreamReader in = new InputStreamReader(s.getInputStream());
BufferedReader bufferedReader= new BufferedReader(in);
String oneLine=bufferedReader.readLine();
System.out.println("客户端收到"+oneLine);
bufferedReader.close();
in.close();
writer.close();
s.close();
}
}
服务器
public class Server {
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
ServerSocket servSocket = new ServerSocket(4242);