服务器线程
package schatserver;
public ServerThread(Socket socket) {
this.socket = socket;
this.start();
}
public void run() {
try {
ObjectInputStream inputStream = new ObjectInputStream(this.socket.getInputStream());
ObjectOutputStream outputStream = new ObjectOutputStream(this.socket.getOutputStream());
container = (Message) inputStream.readObject();
.....
..... etc
并且“消息类”包含在服务器端和客户端
public class Message implements Serializable {
private String login;
private String message;
private String[] users;
private Date time;
public Message(String login, String message){ //for client
this.login = login;
this.message = message;
this.time = java.util.Calendar.getInstance().getTime();
}
public Message(String login, String message, String[] users){//for server
this.login = login;
this.message = message;
this.time = java.util.Calendar.getInstance().getTime();
this.users = users;
}
尝试发送对象“消息”
private static Message message;
public void Connect() {
try {
sock = new Socket(ClientConfig.HOST, ClientConfig.PORT);
System.out.println("Connected with: " + ClientConfig.HOST);
ObjectOutputStream out = new ObjectOutputStream(sock.getOutputStream());
out.writeObject(message);
out.flush();
在这一行得到“java.lang.ClassNotFoundException:socketchatclient.Message”
container = (Message) inputStream.readObject();
有人可以解释我应该如何发送对象消息吗?
套接字聊天客户端。- 这是客户端包