/*
* Created on 2004-12-15
* //該類解析了socket的用戶名 userId,passWord,等待Thread驗證
* 封裝了客戶socket和客戶的userId
* ???根據專家模式有兩種方式:1 讓thread處理
* 2 讓Agent自己處理.在Thread處調用即可
* 這兩種方法哪個更好一些??
*/
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PRintWriter;
import java.net.*;
import java.util.StringTokenizer;
public class Angent {
private Socket socket;
public String msg;//在這里解析,線程類,協議類可以利用
private String userId;
private String password;
private BufferedReader in;
private PrintWriter out;
public String getPassword() {
return password;
}
public Socket getSocket() {
return socket;
}
public String getUserId() {
return userId;
}
public Angent(Socket asocket) {
socket=asocket;
try {
in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
out= new PrintWriter(socket.getOutputStream(),true/*autoflush*/);
msg=in.readLine();
getuser();//初始化字段
} catch (IOException e) {
System.out.println("解析字符錯誤!");
e.printStackTrace();
}
}
//解析命令,檢測合法用戶(用戶首次登錄)
private void getuser() throws IOException{
StringTokenizer t=new StringTokenizer(msg,"http://");
userId=t.nextToken();
password=t.nextToken();
}
public BufferedReader getIn() {
return in;
}
public PrintWriter getOut() {
return out;
}
}
新聞熱點
疑難解答