标题:服务器和客户端程序哪里错了??
只看楼主
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
结帖率:50%
 问题点数:0 回复次数:1 
服务器和客户端程序哪里错了??
为什么这个服务器程序打印不出“5”????
import *;
import *;

class Server
{
        public Server()
        {
              try
              {
                        ServerSocket ss=new ServerSocket(6000);
                        Socket s=ss.accept();
                        System.out.println("1");
                        InputStream in=s.getInputStream();
                        OutputStream out=s.getOutputStream();
                        System.out.println("2");
                        BufferedReader BR=new BufferedReader(new InputStreamReader(in));
                        PrintWriter PP=new PrintWriter(out,true);
                        System.out.println("3");
                        String str=BR.readLine();
                        System.out.println("4");
                        PP.println("服务器已经接收到请求!!");
                        while(str!=null)
                        {
                                System.out.println(str);
                                str=BR.readLine();
                        }
                        System.out.println("5");
                }
                catch(Exception e)
                {
                        e.printStackTrace();
                }
        }
        public static void main(String[] args)
        {
                Server s=new Server();
        }
}
为什么这个客户端程序打印不出“aaaa”????
import *;
import *;

class Client
{
        public Client()
        {
              try
              {
                        Socket s=new Socket(InetAddress.getByName(null),6000);
                        System.out.println("1");
                        InputStream in=s.getInputStream();
                        OutputStream out=s.getOutputStream();
                        System.out.println("2");
                        BufferedReader BR=new BufferedReader(new InputStreamReader(in));
                        PrintWriter PW=new PrintWriter(out,true);
                        System.out.println("3");
                        PW.println("客户端已经接收到回应!!");
                        System.out.println("4");
                        String str=BR.readLine();
                        System.out.println("5");
                        while(str!=null)
                        {
                                System.out.println(str);
                                str=BR.readLine();
                        }
                        System.out.println("aaaa");
              }catch(Exception e)
              {
                        e.printStackTrace();
              }
        }
        public static void main(String[] args)
        {
                Client s=new Client();
        }
}
搜索更多相关主题的帖子: 服务器 客户端 new java 
2008-03-31 14:10
freish
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1223
专家分:437
注 册:2007-6-1
得分:0 
也正在想这个问题
程序可以肯定没错
我想输入流肯定没空才会这样
2008-04-01 21:48



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-206331-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.384261 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved