| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 986 人关注过本帖
标题:麻烦给个注释
只看楼主 加入收藏
wsaaa
Rank: 1
等 级:新手上路
帖 子:136
专家分:0
注 册:2007-5-8
收藏
 问题点数:0 回复次数:1 
麻烦给个注释
import *;
import *;
import java.util.*;
public class Server1
{
    ServerSocket sc;
    Socket s;
    Vector msgbox;
    int counter;
    Server1()
    {
        try
        {
            counter=0;
            Socket s;
            msgbox=new Vector();
        sc=new ServerSocket(9999);
        while(true)
        {
            s=sc.accept();
            new Connection(s).start();
        }
        
        }catch(Exception e){e.printStackTrace();}
        
        
    }
    public static void main(String args[])
    {
        new Server1();
    }
    class Connection extends Thread
    {
        Socket clientsocket;
        int clientcounter;
        PrintStream streamtoclient;
        BufferedReader readfromclient;
        ReadThread rt;
        WriteThread wt;
        Connection(Socket skt)
        {
            
                try
                {
                    clientsocket=skt;
                    streamtoclient=new PrintStream(clientsocket.getOutputStream());
                    readfromclient=new BufferedReader(new InputStreamReader(clientsocket.getInputStream()));
                    clientcounter=0;
                    
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            }
        public void run()
        {
            rt=new ReadThread();
            wt=new WriteThread();
            rt.start();
            wt.start();
        }
        class WriteThread extends Thread
        {
            public void run()
            {
                String str;
                try
                {
                    while(true)
                    {
                        for(int i=clientcounter;i<counter;i++)
                        {
                            str=(String)msgbox.elementAt(i);
                            streamtoclient.println(str);
                            clientcounter++;
                        }
                    }
                    
                }
                catch(Exception e)
                {
                    e.printStackTrace();
                }
            
            }
        }
        class ReadThread extends Thread
        {
            public void run()
            {
                while(true)
                {
                    try
                    {
                        String str;
                        str=readfromclient.readLine();
                        msgbox.addElement(str);
                        counter++;
                    }
                    catch(Exception e)
                    {
                        e.printStackTrace();
                    }
                }
            }
        }
        }
}
这个程序中有很多的问题,有可能的话就给个注释.几个比较迷惑的问题是connection的作用是什么,clientcounter和counter各代表什么,Connection(s).是什么意思,线程里可以套接socket吗?
搜索更多相关主题的帖子: 注释 import java new Vector 
2008-03-26 11:38
wsaaa
Rank: 1
等 级:新手上路
帖 子:136
专家分:0
注 册:2007-5-8
收藏
得分:0 
怎么没有人来回答呀,要不回答我下面的问题也可以吧.不可能是都不会吧,论坛里应该有很多的高手呀!
2008-03-28 07:49
快速回复:麻烦给个注释
数据加载中...
 
   



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

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