Results 1 to 6 of 6
  1. #1
    Jorik is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default Serialization of the messages

    Good day, programmers. I am a student and have a problem.
    So, I have a client and a server, which have own messages (events), e.g., "logOut","RegisterUser" and so on.
    The server passes different messages to the clients (and vice-versa). When the server (or client) receives a message, first it must read 2 byte.
    I want to identify the object which would be created and, afterwards, fill fields in the created object. But I want to do it without "if" and "case".
    I heard that I can identify the type of the object without "if" and "case" using a serialization of the messages. It doesn't exactly concern Java but object-oriented language.
    I spent all day long searching any information about it but couldn’t find anything.
    The problem is that those messages have different size. When I identify the type of the object which I need (reading first two bytes), I will create an instance of class. Then I will fill different fields of this class. That’s why I need this identification.
    An idea flashed across my mind, and I decided to do Factory Message but some time later I refused this idea because different types of messages which are intended for the client and the server had different signature. That’s why I had to use two factories. I didn’t like this.
    I gave this information just because I wanted to show that I had tried to find the solution of this question. I absolutely refused to use Factory and polymorphism.



    How can I do it? Please help.
    p.s. Sorry for my English, I know it a little.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    serialization of the messages
    What do you mean by "serialization of the message"?
    It sounds like you send a message id followed by the message. The messages are each of different format.

  3. #3
    Jorik is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    Yes , I mean exactly what you have said.
    I pass packet which has text format. E.g. , "01james|qwerty".
    "01" - a message identifier which can be an identification of the packet(I can recognize what it is a login or a service message), "james" is a username, "|" is a separator, "qwerty" is a password. I want to create the object using this identifier and serialization.That object has different fields and methods. I can't use Java serialization because my senior teacher has prohibited me from using packets of binary format.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    So now you want to feed the rest of the message to the correct method/constructor, but not use a if or a switch/case to select the code to execute?

  5. #5
    Jorik is offline Member
    Join Date
    Oct 2010
    Posts
    5
    Rep Power
    0

    Default

    I don't know what the type of the object will be. First I want to identify what the object will be(an identification can be message id), create an instance and then fill some fields.

  6. #6
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,899
    Rep Power
    25

    Default

    The question is: how do you decide which class to create to handle the rest of the message?
    You said: "identify the type of the object without "if" and "case"".

    Nothing comes to mind at the moment. Without those two statements, I have no recommendations.

Similar Threads

  1. PM sent box does not list my sent messages.
    By Znote in forum Suggestions & Feedback
    Replies: 4
    Last Post: 04-14-2010, 04:36 PM
  2. Serialization
    By twiggy62 in forum New To Java
    Replies: 2
    Last Post: 02-12-2010, 05:45 AM
  3. about serialization
    By bishnu in forum New To Java
    Replies: 0
    Last Post: 12-19-2008, 10:13 AM
  4. Need help using serialization
    By xcallmejudasx in forum New To Java
    Replies: 0
    Last Post: 12-02-2008, 09:23 PM
  5. Replies: 0
    Last Post: 04-04-2008, 03:47 PM

Posting Permissions

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