Trying send object in a network!!!
I've trying to develop a chat application.And trying to send an object through the network but the server is not receiving it..
Code:
public Boolean sendMessage(Command cmd, String msg)
{
try {
DataObject obj = new DataObject();
obj.setCommand(cmd);
obj.setMessage(msg);
obj.setUserName(myName);
out = new ObjectOutputStream(socket.getOutputStream());
out.writeObject(obj);
out.flush();
System.out.println("Sending Message "+obj.getCommand());
return true;
} catch (Exception ex) {
System.out.println("Error sending message " +cmd.name());
errMsg = ex.getMessage();
return false;
}
}
the data object's(server Side) code is
Code:
ublic class DataObject implements java.io.Serializable {
private Command command;
private String message;
private int userID;
private int toUserID=0;
public DataObject() {
}
public DataObject(Command command, String message,int userID) {
this.command = command;
this.message = message;
this.userID=userID;
}
public Command getCommand() {
return command;
}
public void setCommand(Command command) {
this.command = command;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public int getUserID() {
return userID;
}
public void setUserID(int userID) {
this.userID = userID;
}
public int getToUserID() {
return toUserID;
}
public void setToUserID(int toUserID) {
this.toUserID = toUserID;
}
}
There is like difference in data object of client its something like this
Code:
public class DataObject implements java.io.Serializable {
private Command command;
private String message;
private int userID;
private int toUserID;
public DataObject()
{}
public DataObject(Command command, String message,String userName) {
this.command = command;
this.message = message;
this.userID=Integer.parseInt(userName);
}
public Command getCommand() {
return command;
}
public void setCommand(Command command) {
this.command = command;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getUserName() {
return Integer.toString(userID);
}
public void setUserName(String userName) {
this.userID = Integer.parseInt(userName);
}
public String getTouser() {
return Integer.toString(toUserID);
}
public void setTouser(String touser) {
this.toUserID = Integer.parseInt(touser);
}
}
I've converted the int to string in userID and toUser is this might be the problem??
Plz help..