Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8646231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:45:11+00:00 2026-06-12T12:45:11+00:00

From my client/server I receive serialized data, once the data is deserialized, it goes

  • 0

From my client/server I receive serialized data, once the data is deserialized, it goes into a command handler where receivedData.Action is the ClientMessage:

Command._handlers[receivedData.Action].Handle(receivedData.Profile);

The command handler will work out the client message and return the response that should be given to the client.

I have an enum for the client messages as follow:

public enum ClientMessage
{
    INIT = 1,
    NEW_PROFILE,
    UPDATE_PROFILE_EMAIL,
    UPDATE_PROFILE_PASSWORD,
    UPDATE_PROFILE_PHONE,
    UPDATE_PROFILE_DATE,
    UPDATE_PROFILE_SECRET_ANSWER,
    UPDATE_PROFILE_POSTAL_CODE,
    UPDATE_SUCCESS,
    PING,
    PONG,
    QUIT
}

What I am having a difficult is how to have all the actions written, for example:

  • Should I have a separated enum for what the client sends and another for what the server should reply with ?
  • Or should I have a single enum with all messages and follow it as requested ?
  • Or how should I go about defining the messages and handling it ?

This is what my server/client currently does just to give you a better view:

  1. Server starts
  2. Client connects
  3. Client send auth to server
  4. Server verify client and send connected approval message
  5. Client will from there start sending and updating profiles to the server

This is roughly an example only.

IPacketHandler

public interface IPacketHandler
{
    MyCommunicationData Handle(ProfileData profile);
}

Command

public class Command
{
    public static Dictionary<ClientMessage, IPacketHandler> _handlers = new Dictionary<ClientMessage, IPacketHandler>()
    {
        {ClientMessage.INIT, new Init()},
        {ClientMessage.NEW_PROFILE, new NewProfile()},
        {ClientMessage.UPDATE_PROFILE_EMAIL, new UpdateEmail()},
        {ClientMessage.UPDATE_PROFILE_PASSWORD, new UpdatePassword()},
        {ClientMessage.UPDATE_PROFILE_PHONE, new UpdatePhone()},
        {ClientMessage.UPDATE_PROFILE_DATE, new UpdateDate()},
        {ClientMessage.UPDATE_PROFILE_SECRET_ANSWER, new UpdateSecretAnswer()},
        {ClientMessage.UPDATE_PROFILE_POSTAL_CODE, new UpdatePostalCode()},
        {ClientMessage.UPDATE_SUCCESS, new Success()},
        {ClientMessage.PING, new Ping()},
        {ClientMessage.PONG, new Pong()},
        {ClientMessage.QUIT, new Quit()},
    };
}

Example of the INIT

public class Init : IPacketHandler
{
    public MyCommunicationData Handle(ProfileData profile)
    {
        // Some verification to auth the client here 
        // bla bla
        // return response
        return new MyCommunicationData() { Action = ClientMessage.CONNECTED };
    }
}

PS: If my title is off and you have a better suggestion let me know or if you can go ahead and update it, I was not sure of how to describe this in English.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:45:13+00:00Added an answer on June 12, 2026 at 12:45 pm

    If your question is about how to design the class and interactions as I understood it, then I would – and it’s totally dependant on the specifics of your application – separate this big Enumerations type into separate, smaller ones that are more descriptive of what they do, and of your intentions, for example, ProfileAction, ActionResult, PingStatus etc.. Then when you’re using these enums, you make sure that you get compiler-time checks that you’re doing it correctly, otherwise, what you’re doing is almost like just passing strings.

    It also has to do with sticking to Single Responsibility principle in OO design: an object should have single responsibility. Your enum as it stands now has more than one responsibility.

    With issues like these, I find it helpful to look at what .NET framework does: for example look at Ping class and how it uses PingStatus enumerations and other enumerations as well.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently develop a server application which has to receive serialized data from clients,
I just want to transfer (send or receive) a hash from client to server.
I'm trying to use __doPostBack to pass some data from client to server side.
The requirement of the TCP server: receive from each client and send result back
I send binary data from client (Debian 6.0.3) to server (Windows Server 2003). To
I have a server application that receives some special TCP packet from a client
I am building a client that can recieve information from the server and from
I want to send more than one image file from client to server for
In my java application I want to transfer some Images from client to server.
When a client connection with the SQL Server (from client side ) is cut,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.