麻烦给个注释
import java.net.*;import java.io.*;
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
----------------解决方案--------------------------------------------------------
怎么没有人来回答呀,要不回答我下面的问题也可以吧.不可能是都不会吧,论坛里应该有很多的高手呀!
----------------解决方案--------------------------------------------------------