package moshi;import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;import Common.Message;public class Xiancheng extends Thread
{
Socket s;
public Xiancheng(Socket s)
{
this.s = s;
}
public void run()
{
try
{
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
Message m = (Message)ois.readObject();
System.out.println(m.getSender()+"对"+m.getGetter()+"说"+m.getCon());
Xiancheng xc = Xianchengbiaoshi.getXiancheng(m.getGetter());
//System.out.println(xc.getId());
Xianchengbiaoshi.cs(m.getGetter());
ObjectOutputStream oos = new ObjectOutputStream(xc.s.getOutputStream());
oos.writeObject(m);
//System.out.println(m.getSender()+"给"+m.getGetter()+"说:"+m.getCon());
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package moshi;import java.util.HashMap;public class Xianchengbiaoshi
{
public static HashMap<String, Xiancheng> hm = new HashMap<String,Xiancheng>();
public static void addXiancheng(String uid,Xiancheng xt)
{
hm.put(uid,xt);
//System.out.println(hm.get(uid));
}
public static Xiancheng getXiancheng(String uid)
{
return (Xiancheng)hm.get(uid);
}
public static void cs(String uid)
{
System.out.println((Xiancheng)hm.get(uid));
}
}
import java.io.ObjectOutputStream;
import java.net.Socket;import Common.Message;public class Xiancheng extends Thread
{
Socket s;
public Xiancheng(Socket s)
{
this.s = s;
}
public void run()
{
try
{
ObjectInputStream ois = new ObjectInputStream(s.getInputStream());
Message m = (Message)ois.readObject();
System.out.println(m.getSender()+"对"+m.getGetter()+"说"+m.getCon());
Xiancheng xc = Xianchengbiaoshi.getXiancheng(m.getGetter());
//System.out.println(xc.getId());
Xianchengbiaoshi.cs(m.getGetter());
ObjectOutputStream oos = new ObjectOutputStream(xc.s.getOutputStream());
oos.writeObject(m);
//System.out.println(m.getSender()+"给"+m.getGetter()+"说:"+m.getCon());
} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
package moshi;import java.util.HashMap;public class Xianchengbiaoshi
{
public static HashMap<String, Xiancheng> hm = new HashMap<String,Xiancheng>();
public static void addXiancheng(String uid,Xiancheng xt)
{
hm.put(uid,xt);
//System.out.println(hm.get(uid));
}
public static Xiancheng getXiancheng(String uid)
{
return (Xiancheng)hm.get(uid);
}
public static void cs(String uid)
{
System.out.println((Xiancheng)hm.get(uid));
}
}
if(xc == null){
System.out.println("xc为空");
}else{
if(xc.s == null){
System.out.println("s"为空);
}
}
if(xc == null){
System.out.println("xc为空");
}else{
if( null == xc.s){
System.out.println("s"为空);
}换成,上楼的回答可能报控制异常