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 7638367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:09:36+00:00 2026-05-31T08:09:36+00:00

I have developed a TCP server by async pattern under .net4 in c# that

  • 0

I have developed a TCP server by async pattern under .net4 in c# that handles hundreds of TCP connections simultaneously. It has been working without any problems for months, so, I have experiences with async sockets & co. in .net.

Now I have another project: this time I have to develop a TCP client, that connects to a server (one and only server, not more!) via TCP and sends commands to it, get responses and also handles incoming, server initiated notification messages.

Now I am a little bit confused. I am looking for the most efficient way to implement these features:

  • it must send some commands asynchronously and get their response also asynchronously
  • some commands should be sent synchronously and get response also synchronously
  • it must listen for incoming notification TCP messages. So, these messages are initiated from server side, they don’t come as a response for a request

Which do you think the best pattern to implement it? How to listen incoming, server initiated requests, while also handling client initiated requests?

Thanks!

Request sample:

02/00059/O/60/07656765/2/1/1/50617373776F7264//0100//////61 

Response sample:

00/00019/R/60/A//6D 

Notification sample: 00/00114/O/52/0011456046589/01123404543////////////0000/568112131424////3//43424‌1///0//////56312389921/020100///C3

  • 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-05-31T08:09:37+00:00Added an answer on May 31, 2026 at 8:09 am

    It really depends on how the server formats the commands that are coming in. Let’s say, for example, they are in the form ” “.

    The first thing I would do is write a socket class that handles reading data in and raising an event (say, OnLine) for each “line” received (this is just an example, I have no idea what kind of format your command and messages are in).

    I would then implement a class that has this text-socket as a member, and subscribe to the line received event. This class would also have a dictionary of delegates that map to the possible commands that can be received from the server, e.g:

    public class MyClient
    {
        private delegate void CommandHandler(string data);
        private TextSocket socket_ = new TextSocket(); // text socket we created
    
        private Dictionary<string, CommandHandler> cmdMap_ = new Dictionary<string, CommandHandler>();
    
        public MyClient()
        {
            // Initialise our map full of delegates
            cmdMap_["CMD1"] = (data) => { /* handle this command */ };
            cmdMap_["CMD2"] = (data) => { /* handler for this one */ };
    
            socket_.OnLineReceived += (line) 
            {
                if(!string.IsNullOrEmpty(line)) // sanity check
                {
                    string cmd;
                    string data;
                    int pos = line.IndexOf(' ');
                    if(pos != -1)
                    {
                        cmd = line.Substring(0, pos);
                        data = line.Substring(pos + 1);
                    }
                    else
                        cmd = line;
    
                    if(cmdMap_.ContainsKey(cmd))
                        cmdMap_[cmd](data);
                }
            }; 
        }
    }
    

    Note, I have used lambdas here, but sure don’t need to.

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

Sidebar

Related Questions

Hello I developed a multi-threaded TCP server application that allows 10 concurrent connections receives
I have developed a small server that recives connections (using basically the example here:
I have a Java app, connecting through TCP socket to a server developed in
I have developed a TCP server according to your advises: High performance TCP server
I have a small TCP server that listens on a port. While debugging it's
I have developed a server to listen in a TCP port .. and i
I have developed (TCP) server to listen to a client and interact with it.
I have developed a VB.NET WCF service that recives and sends back data. When
We have developed a website that uses MVC, C#, and jQuery. In one of
We have developed a webservice that sits and runs in the context of a

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.