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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:01:50+00:00 2026-06-04T20:01:50+00:00

I made a simple protocol for my game: b = bool i = int

  • 0

I made a simple protocol for my game:

b = bool
i = int
sINT: = string whose length is INT followed by a : then the string
m = int message id.

Example:

m133s11:Hello Worldi-57989b0b1b0

This would be:

Message ID 133
String 'Hello World' length 11
int -57989
bool false
bool true
bool false

I did not know however that TCP could potentially only send PART of a message. I’m not sure exactly how I could modify this such that I can do the following:

on receive data from client:
use client's chunk parser
process data
if has partial message then try to find matching END
if no partial messages then try to read a whole message

for each complete message in queue, dispatch it

I could do this by adding B at the beginning of a message and E at the end, then parsing through for the first char to be B and last to be E.

The only problem is what if
I receive something silly in the middle that does not follow the protocol. Or, what if I was supposed to just receive something that is not a message and is just a string. So if I was somehow intended to receive the string HelloB, then I would parse this as hello and the beginning of a message, but I would never receive that message because it is not a message.

How could I modify my protocol to solve these potential issues? As much as I anticipate only ever receiving correctly formed messages, it would be a nightmare if one was poorly encoded and set everything out of whack.

Thanks

I decided to add the length at the beginning and keep track of if I’m working on a message or not:
so:

p32m133s11:Hello Worldi-57989b0b1b0

I then have 3 states, reading to find ‘p’, reading to find the length after ‘p’ or reading bytes until length bytes have been read.

What do you think?

It seems to work great.

  • 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-04T20:01:51+00:00Added an answer on June 4, 2026 at 8:01 pm

    What you are doing is pretty old-school, magnetic tape stuff. Nice.

    The issue you might have is that if a part of the message is received, you cannot tell if you are partway through a token.

    E.g. if you receive:

    m12
    

    Is this Message 12, or is it the first part of message 122?

    If you receive:

    i-12
    

    Is this an integer -12 or is it the first part of an integer -124354?

    So I think you need to change it so that the message numbers are fixed width (e.g. four digits), the string length is fixed (e.g. 6 digits) and the integer width is fixed at 10 digits.

    So your example would be:

    m_133s____11:Hello Worldi____-57989b0b1b0
    

    That way if you get the first part of a message you can store it and wait for the remainder to be received before you process it.

    You might also consider using control characters to separate message parts. There are ascii control codes often used for this purpose, RS, FS, GS and US. So a message could be

    [RS]FieldName[US]FieldValue[RS]fieldName[US]FieldValue[GS].
    

    You know when you have a complete message because the [GS] marks the end. You can then divide it up into fields using the [RS] as a separator, and split each into name/value using the [US].

    See http://en.wikipedia.org/wiki/C0_and_C1_control_codes for a brief bit of information.

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

Sidebar

Related Questions

Assume I have simple protocol implemented over TCP, where each message is made up
We made a simple application and using GoogleAppEngineLauncher (GAEL) ran that locally. Then we
I made simple procedure just to demonstrate CREATE PROCEDURE `demo`(demo_int int) BEGIN DECLARE minid
i made simple game by java , it's about tennis background and tennis ball
I made a simple game in silverlight for windows phone. When I try to
When I have made simple single thread games I implemented the game logic in
I made simple email in wordpress but it would only send email to the
I've made simple neural network for mouse gestures recognition (inputs are angles)and I've used
Visual Studio 2008 (vb.net) I made simple anivirus but when I make Full scan
On Windows, testing different OSes is made simple using VMs. Is there a simple

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.