标题:Hashtable问题
只看楼主
ttrr550
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2006-11-5
结帖率:0
 问题点数:0 回复次数:2 
Hashtable问题

在使用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!");
}
}

搜索更多相关主题的帖子: Hashtable 
2006-12-03 14:54
千里冰封
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:灌水之王
等 级:版主
威 望:155
帖 子:28477
专家分:59
注 册:2006-2-26
得分:0 

你应该声明为
Hashtable<String,loginThread>


可惜不是你,陪我到最后
2006-12-03 15:00
ttrr550
Rank: 1
等 级:新手上路
帖 子:59
专家分:0
注 册:2006-11-5
得分:0 
thank you !!

2006-12-03 15:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-106972-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.049843 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved