📄 client.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 + -