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

  • SEARCH
  • Home
  • 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 8456615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:35:25+00:00 2026-06-10T12:35:25+00:00

I have a multithread server, waiting for socket connections. The first exchange of message

  • 0

I have a multithread server, waiting for socket connections.

The first exchange of message is always of the same type, the clients sends an object with the authentication details(userid/pwd), the server checks it and reply to the server if the authentication has been passed or not.

After this first exchange of messages, the client will send some requests, corresponding to various tasks the server is able to execute.
How do i model those eterogeneous requests? In particular my question regards the type of object sent between client and server with InputObjecStream/OutputObjectStream

I had 2 ideas:

  1. Using a “generic message” object, with 2 attributes: a task identifier and an HashMap without generics, able to carry various type of parameters requested for executing the task.

  2. An object for every type of task, this solution is “cleaner”, but I don’t know how to make the server understand the type of the message received, I thought about a series of object casting of the received message from the client to every possible “specific task message”, ignoring the many CastException. It sounds just bad, is there any way to avoid this?

  • 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-10T12:35:27+00:00Added an answer on June 10, 2026 at 12:35 pm

    The first approach is very generic but will be hard to maintain. After a while you’ll notice that you no longer remember what kind of objects should be in this generic map. You’ll have to keep the dictionary in sync.

    The second approach is much better. Essentially you receive an abstract Request object with various subclasses. The base class can hold some general information. Normally you would use polymorphism and implement the action in each subclass, overriding abstract method from Request class. But you can’t because request object would have to hold server-side logic.

    The best you can do here is visitor design pattern. With it, for the price of slightly obscuring your code, you’ll get very generic and safe design. instanceof tends to be ugly after some time.

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

Sidebar

Related Questions

I have a multithread server that uses one MSSQL which each client should have
I have a Simple Multithread Server, the code of Threads looks like this: public
My multithread program crash. I have .core file. I load it and thread apply
I'm trying to multithread something and i have my program set up such that
So I have a website already set up, and I need a comet server
I have an ASP.NET page that gets a list of game server ip addresses
I'm trying to build a simple multithreaded tcp server. The client connects and sends
I have read some tips that multithread implementation largely depends on the target OS
I have created a .Net application to run on an App Server that gets
I've coded a multithreaded server and it can handle many clients connecting at once.

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.