日期:2014-05-20 浏览次数:20890 次
public class Message implements java.io.Serializable{
private String Username;
private String cmd;
private String MSG;
Message(String Username,String cmd,String MSG){
this.setUsername(Username);
this.setCmd(cmd);
this.setMSG(MSG);
}
public void setMSG(String mSG) {
MSG = mSG;
}
public String getMSG() {
return MSG;
}
public void setCmd(String cmd) {
this.cmd = cmd;
}
public String getCmd() {
return cmd;
}
public void setUsername(String username) {
Username = username;
}
public String getUsername() {
return Username;
}
}
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class s{
public static void main(String[] args){
try {
ServerSocket s=new ServerSocket(9528);
Socket c=s.accept();
ObjectOutputStream Tc=new ObjectOutputStream(c.getOutputStream());
Message m=new Message("","","aaaaaa");
Tc.writeObject(m);
Tc.flush();
m.setMSG("bbbbbb");
Tc.writeObject(m);
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
public class c{
public static void main(String[] args) throws UnknownHostException, IOException, ClassNotFoundException{
Socket c=new Socket("127.0.0.1",9528);
ObjectInputStream Fs=new ObjectInputStream(c.getInputStream());
Message m=(Message)Fs.readObject();
System.out.println(m.getMSG());
m=(Message)Fs.readObject();
System.out.println(m.getMSG());
}
}
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class s{
public static void main(String[] args){
try {
ServerSocket s=new ServerSocket(9528);
Socket c=s.accept();
ObjectOutputStream Tc=new ObjectOutputStream(c.getOutputStream());
Message m=new Message("","","aaaaaa");
Tc.writeObject(m);
Tc.flush();
Tc.reset();
m.setMSG("bbbbbb");
Tc.writeObject(m);
System.in.read();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}