| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 642 人关注过本帖
标题:服务器和客户端程序哪里错了??
只看楼主 加入收藏
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
快速回复:服务器和客户端程序哪里错了??
数据加载中...
 
   



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

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