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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T06:23:55+00:00 2026-06-12T06:23:55+00:00

While I’m a newbie in socket programming, as I was writing a simple tcp

  • 0

While I’m a newbie in socket programming, as I was writing a simple tcp server-client program, I found the stream-based api is not that convenient to use.

My program is simply simple:

  1. The client connects to a server
  2. The server continuously send messages to client, in a unexpectable interval
  3. The client receives message and do work according to the data contained in message

However, using the stream-based api, I have to:

  • Define a message delimiter / separator
  • Use a while loop to read data from stream
  • Concat all bytes, try to find the delimiter
  • If delimiter exists, split the data, extract the message

That’s a lot work, even more than the entire logic of my program, so I’m wondering is there a library could do stuffs above for me, with such library I can program like this:

// Server
TcpListenerEx server = new TcpListenerEx();
TcpClientEx client = server.Accept();
client.SendMessage(new StringMessage("hello world"));

// Client
TcpClientEx client = new TcpClientEx();
client.Connect("localhost", 8989);
while (true) {
    IMessage message = client.ReadMesage();
    // Do work acording to message
}

Any suggestion would be welcome, thanks.

  • 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-12T06:23:57+00:00Added an answer on June 12, 2026 at 6:23 am

    Embedding a delimiter in a byte-stream is not as easy as it might look. You’d have to deal with the message accidentally containing the delimiter. This leads to lots of nasty detection and escaping code.

    A very simple way to frame messages is to prepend a length-prefix. On the sender you serialize the message into a buffer, then write the length, then write the buffer. The receiver first reads 4 bytes to obtain the length. Then it reads the body.

    This is not built into .NET, probably because every binary protocol is slightly different.

    All of this is so simple that it is unlikely you will find a library. Such a protocol can be written in a few dozen lines. My recommendation is to just do it yourself.

    If you want to structure your message, though, there is a great library: protobuf-net (Google protocol buffers for .NET). It does message framing for you and also the serialization in a very sane way. It supports protocol versioning nicely.

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

Sidebar

Related Questions

While trying to install a program from source I found that it installed libraries
While developing an application using gwt in ecliplse crashed. Now the server is running
While playing with standard library i've found a strange difference between python2 and python3.
While refactoring my code base I found a piece of code which I'd like
While programming with python I am often confused with the following ambiguity: should it
While listening through Stanford's Programming Abstractions course, I come across some piece of code
While trying to call an EJB made using NETbeans (using jdk1.7) from a client
While working on Hadoop Implementation in Pseudo-Distributed Operation, I found following exception of JAVA_HOME
while setting up a simple Rails app, I met an issue i never had
While converting database project to SSDT and upgrading to SQL Server 2012 I need

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.