在使用Hashtable时的问题??
package test; //Server.java
import java.util.*;
import java.io.*;
import java.net.*;
public class chatserver {
String str[]={"one","two","three","four","five","six","seven","night","nine"};
public chatserver(Socket player,int i,Hashtable<Object,Object> saveThread) {
try{
loginThread thread=new loginThread(player);
saveThread.put(str[i],thread);
thread.start();
System.out.println(saveThread.get("one"));
//saveThread.get("one").getConnectServer(); //错误.... 从Hashtable中取出的是不是loginThread的对象嘛?
//上面一句是要实现 取出保存的一个线程 然后执行此线程的getConnectServer()方法..
//我该怎么做实现上面说的...
thread.getConnectServer();
}
catch(Exception ex)
{
System.err.println(ex);
}
}
public static void main(String[] args)throws IOException{
ServerSocket serverSocket=new ServerSocket(8002);
System.out.println("Server Started!");
Hashtable<Object,Object> saveThread=new Hashtable<Object,Object>();
int i=0;
while(true)
{
Socket player=serverSocket.accept();
try{
new chatserver(player,i,saveThread);
}
catch(Exception e)
{
}
i++;
}
}
}
class loginThread extends Thread{
private Socket connectToClient1;
Socket connectToServer;
public loginThread(Socket PLAYER){
connectToClient1=PLAYER;
}
public void getConnectServer(){
//connect to server!
try{
//connectToServer=new Socket("localhost",6666);
System.out.println("test~~!!!");
}
catch(Exception e){
}
}
public void run(){
System.out.println("run~~!!!");
}
}
package test; //client.java
import java.io.*;
import java.net.*;
public class client {
public client() {
}
public static void main(String[] args)throws IOException {
Socket connectToServer=new Socket("localhost",8002);
System.out.println("finished connected!");
}
}