[java]代码库
package com.qq.MyClient;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import com.qq.user.SendToMessage;
import com.qq.user.user;
public class MyClient {
public Socket socket;
public Socket getSocket() {
return socket;
}
ExecutorService threadPool;
public boolean fistLogin(user u){
boolean b=false;
try {
socket=new Socket("127.0.0.1",8000);
threadPool=Executors.newCachedThreadPool();
ObjectOutputStream oos=new ObjectOutputStream(socket.getOutputStream());
oos.writeObject(u);
ObjectInputStream ois=new ObjectInputStream(socket.getInputStream());
SendToMessage sm=(SendToMessage)ois.readObject();
if("1".equals(sm.getMessType())){
b=true;
MyClientThread mct=new MyClientThread(socket);
magaeMyClientThread.addMyClientThread(u.getUserId(), mct);
threadPool.execute(mct);
}
} catch (Exception e) {
e.printStackTrace();
}
return b;
}
}