qq_38805084
zxdream_727
2017-12-02 09:27

java 服务端与用户端连接问题

  • java
  • udp 服务端 客户端

用户端:
InputStream is = client.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);//输入
OutputStream os = client.getOutputStream();
PrintWriter print=new PrintWriter(os);//输出

    System.out.println(br.readLine());//输入:L登录;R注册;Q退出程序
    print.write(s.next());//用户输入选择后发给服务端
    print.close();
    System.out.println(br.readLine());//请输入用户名
    print.write(s.next());//用户名发给服务端
    print.close();
    System.out.println(br.readLine());//请输入密码
    print.write(s.next());//密码发给服务端
    print.close();

服务端
InputStream is = client.getInputStream();
InputStreamReader isr=new InputStreamReader(is);
BufferedReader br=new BufferedReader(isr);//输入
OutputStream os = client.getOutputStream();
PrintWriter print=new PrintWriter(os);//输出

    System.out.println("开始交互");
    print.write("输入:L登录;R注册;Q退出程序");
    print.close();

    String cho = br.readLine();
    System.out.println(cho);
    switch(cho) {
        case "L":
            print.write("请输入用户名:");
            print.close();
            String userName = br.readLine();
            print.write("请输入密码:");
            print.close();
            String password = br.readLine();
            break;

提示后,输入L后显示null,然后阻塞

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答