⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 client.java

📁 JAVA实现的聊天工具,可以容纳最多10个用户 1.本系统需要JDK1.5 或更高版本的支持。 2.serverDatabase为服务器端的数据文件. 若使用现有数据,可用帐号:1, 密码
💻 JAVA
字号:
//the main class
import java.io.*;
import java.net.*;
import java.util.concurrent.*;
public class Client{
	private static Client aClient=null;
	private static int threadPoolSize=5;
	
	private FriendsDatabase friendsDatabase=null;
	//private ClientControlThread aControlThread;
	//private ServerSocket clientSocket=null;
	//private Socket tempSocket=null;	
	//private Thread[] threadPool;
	//private ExecutorService tpes;
	//private static boolean signal=true;
	private Thread initiateThread;	
	
	public static void main(String[] args){
		aClient=new Client();
		aClient.friendsDatabase=new FriendsDatabase();
		aClient.initiateThread=new Thread(new ClientInitiateGUI(),"ClientInitiateThread");
		aClient.initiateThread.start();
		//aClient.initiate();
	}
	
	/*
	
	//thread pool to handle request from clients and server
	private void setupThreadPool(){
		tpes = Executors.newFixedThreadPool(threadPoolSize);
		threadPool = new Thread[threadPoolSize];
		for(int i=0;i<threadPoolSize;i++){
			ClientThread ct=new ClientThread();
			threadPool[i]=new Thread(ct,"ClientThread"+i);
			tpes.execute(threadPool[i]);
		}		
	}
	
	private void listen(){
		try{
			clientSocket=new ServerSocket(4445); //listen port 4445 for inform from server and friends
		}catch (IOException e) {
            System.err.println("Could not listen on port: 4445.");            
        }
        
        while(signal){
        	try{
        		tempSocket=clientSocket.accept();        		
        	}catch(IOException e){
        		System.out.println(e+" Server "+e.getMessage());
        	}
        	ClientThread.processRequest(tempSocket);
        }        
	}
	
	private void startControlThread(){
		aControlThread=new ClientControlThread();
		aControlThread.start();
	}*/
	
	static FriendsDatabase getFriendsDatabase(){
		if(aClient.friendsDatabase==null){
			System.out.println("Warning: to return null friendsDatabase!");
		}
		return aClient.friendsDatabase;
	}
	
	static void serverQuit(){
		//aClient.aControlThread.serverQuit(); //deal with ClientControlThread's socket,streams and status		
	}
	
	static void exit(){
		//aClient.aControlThread.serverQuit(); //shutdown ClientControlThread's socket and streams
		//aClient.tpes.shutdown();
		//signal=false;
		//if(id>0)
			//ClientIO.writeFriendsDatabase(aClient.friendsDatabase,"clientFriendsDatabase"+String.valueOf(id)); //save database
		System.exit(1);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -