| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1012 人关注过本帖
标题:我的Socket哪里出错了?急急急急!!!
取消只看楼主 加入收藏
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
结帖率:50%
收藏
 问题点数:0 回复次数:1 
我的Socket哪里出错了?急急急急!!!
为什么我在运行时,会没有反应??好像出现死锁了!
客户端:
import *;
import *;

class Client
{      
      Socket S;
        BufferedReader BR;
        PrintWriter BW;
        InputStream IS;
        OutputStream OS;

      public void put()
      {
            try
            {
                      Socket S=new Socket(InetAddress.getByName(null),6000);
                      IS=S.getInputStream();
                      OS=S.getOutputStream();
                      BR=new BufferedReader(new InputStreamReader(IS));
                    BW=new PrintWriter(OS);
                    BW.print("Hello");
                    System.out.println(BR.readLine());
                    BR.close();
                    BW.close();
                    IS.close();
                    OS.close();
                    S.close();
            }
            catch(Exception e)
            {
                    e.printStackTrace();
            }
      }
        public static void main(String[] args)
        {
                Client S1=new Client();    
              S1.put();
        }
}
服务器段:
import *;
import *;

class Server
{
        public void pet()
        {
                Socket So;
                BufferedReader BR;
                PrintWriter BW;
                InputStream IS;
                OutputStream OS;
        
                try
                {
                        ServerSocket ss=new ServerSocket(6000);
                        So=ss.accept();
                        IS=So.getInputStream();
                        OS=So.getOutputStream();
                    BR=new BufferedReader(new InputStreamReader(IS));
                    BW=new PrintWriter(OS);        
                    BW.print("Welcome to here!!");
                    System.out.print(BR.readLine());
                    BR.close();
                    BW.close();
                    IS.close();
                    OS.close();
                    So.close();
                    ss.close();
                }
                catch(Exception e)
                {
                        e.printStackTrace();
                }
        }
        public static void main(String[] args)
        {
                Server S1=new Server();    
              S1.pet();
        }
}

[[it] 本帖最后由 Javapet 于 2008-3-26 14:07 编辑 [/it]]
搜索更多相关主题的帖子: Socket 
2008-03-25 17:36
Javapet
Rank: 1
等 级:禁止访问
帖 子:80
专家分:0
注 册:2008-1-5
收藏
得分:0 
改了,运行时,还是没有反应,请问是怎么回事啊?请指教!
2008-03-25 20:09
快速回复:我的Socket哪里出错了?急急急急!!!
数据加载中...
 
   



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

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