1
import java.net.*;

import java.io.*;

import java.util.*;

public class ChatServer{

public static void main(String[] args)throws Exception{

ServerSocket svSocket =null;

//Vector threads 为ServerThread集合

Vector threads = new Vector();

//开始监

System.out.println ("listening...");

try {

//创建服务端套接口

svSocket = new ServerSocket(5555);

}catch (Exception ex) {

System.out.println ("Server create ServerSocket failed!");

return;

}

try{

int nid = 0;

//监听是否有端连接

while(true){

Socket socket = svSocket.accept();

System.out.println ("accept a client");

//创建一个新的ServerThread

ServerThread st = new ServerThread(socket,threads);

//为客户配一个ID号

st.setID(nid );

threads.add(st);

new Thread(st).start();

//向所广播有新客户端连接

for(int i=0;i 追问
这是什么
-

下面是更多关于泥巴潭的问答

最佳贡献者

你的回答

单击“发布您的答案”,即表示您同意我们的服务条款