Results 1 to 7 of 7
  1. #1
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default 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..
    Java 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
    Java 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
    Java 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..

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    You cannot serialise one class and expect to deserialise it into another class.
    Doesn't matter if the names are the same...they have to be the same class, and the same version, etc etc.

    I'm surprised you're not getting an exception when it's attempting to deserialise it.

  3. #3
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    It receives the connection.. Connects to the socket. When i try to send object it doesn't receives. When i connect and type through Telnet it receives the object received message.
    BTW i've recoded the server dataobject same to as client dataobject..

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    Quote Originally Posted by G.rocks View Post
    It receives the connection.. Connects to the socket. When i try to send object it doesn't receives. When i connect and type through Telnet it receives the object received message.
    BTW i've recoded the server dataobject same to as client dataobject..
    What do you mean by recoded?
    Are they no referencing the exact same class?

  5. #5
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    Not it different.. in client i've converted the int value of user and to user to string.. And i've change the of user and touser to string..

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,863
    Rep Power
    19

    Default

    You're going to have to give us a better idea what's actually happening.
    Is this code doing anything?
    Java Code:
                out = new ObjectOutputStream(socket.getOutputStream());
                out.writeObject(obj);
                out.flush();

  7. #7
    G.rocks is offline Member
    Join Date
    Jul 2010
    Posts
    7
    Rep Power
    0

    Default

    There an object called DataObject it stores username, command(an another type of user which has sets of enum commands),message(what other side receives) when you called sendMessage() which is in client calls the method and set the username(Id in above case) , command, and message. then it send that dataobject through the socket the
    out = new ObjectOutputStream(socket.getOutputStream());
    out.writeObject(obj);
    out.flush()
    the socket here is the socket of the server..which i predefined it..

Similar Threads

  1. Send selective objects in a class over network
    By RDReavis in forum Advanced Java
    Replies: 2
    Last Post: 01-18-2010, 08:45 AM
  2. sending object through network/socket
    By skandalouz in forum Networking
    Replies: 1
    Last Post: 12-24-2009, 07:34 AM
  3. how to send data to network printer
    By santhosh_el in forum AWT / Swing
    Replies: 3
    Last Post: 10-06-2009, 01:21 PM
  4. Send object via web service, with a java.sql.Timestamp attribute
    By diegofsza in forum Enterprise JavaBeans (EJB)
    Replies: 0
    Last Post: 08-15-2009, 11:40 PM
  5. problem data send from network
    By MS_Dark in forum Networking
    Replies: 1
    Last Post: 06-30-2009, 08:32 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •