红雨 国产老电影:请高手帮忙调试一下这个程序一部分,其余在另一个问题里

来源:百度文库 编辑:神马品牌网 时间:2024/04/28 08:00:03
程序1
import java.io. *;
import java.net.*;
import java.util. *;
public class ChatServer
{
public static void main(String args[])
{
ServerSocket server=null;
Socket you=null;
Hashtable peopleList; //存放与各聊天者客户端通信的服务器线程的散列表。
peopleList=new Hashtable();
try
{
server=new ServerSocket(6666);
System.out.println ("启动监听成功!") ;
}
catch(IOException el)
{
System.out.println ("启动监听失败!") ;
}
while(server!=null)
{
try {
you=server.accept(); //建立和客户端的连接的套接字
InetAddress address=you.getInetAddress();
System.out.println("收到链接:用户的IP:"+address);
}
catch (IOException e) {}
if(you!=null)
{
Server_thread peopleThread=new Server_thread(you,peopleList);
peopleThread.start(); //与该客户端通信的服务器线程开始启动。
}
else {
continue;
}
}
}
}

class Server_thread extends Thread
{
String name=null,sex=null; //聊天者的昵称和性别
Socket socket=null;
File file=null;
DataOutputStream out=null;
DataInputStream in=null;
Hashtable peopleList=null;
Server_thread(Socket t,Hashtable list)
{
peopleList=list;
socket=t;
try {
in=new DataInputStream(socket.getInputStream());
out=new DataOutputStream(socket.getOutputStream());
}