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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:37:59+00:00 2026-05-25T21:37:59+00:00

I have an Arduino microcontroller with a Sparkfun WiFly shield . I build a

  • 0

I have an Arduino microcontroller with a Sparkfun WiFly shield.

I build a simple program in C#/.NET that connects to the Arduino using System.Net.Sockets:

Socket Soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

public void SendMsg(string msg)
{
    try
    {
        byte[] buffer = StrToByteArray(msg);
        if (Soc.Connected)
            Soc.Send(buffer);
        else
        {
            Soc.Connect(this.remoteIP);
            Soc.Send(buffer);
        }
    }
    catch (Exception e){}
}

On the arduino I have:

while(SpiSerial.available() > 0) {
    byte b = SpiSerial.read();
    Serial.println(b);
}

When a socket connection does a handshake, I get: “*OPEN*” and when closed, I get: “*CLOS*“.

The problem is that I get the messages one byte by another and sometimes I don’t get the full message on one while loop.

So if I use the code I showed above on the Arduino, my serial terminal looks like:

*
O
P
E
N
*
T
E
S
T
*
C
L
O
S
*

So how can I figure out the message the PC is trying to send?

I know I need somehow to use a special byte that will symbolise the end of my message. (A special byte that I won’t use in my message, only to symbolise the end of a message)

But how can I do it? And which byte to use?

  • 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-25T21:38:00+00:00Added an answer on May 25, 2026 at 9:38 pm

    You need to design your own protocol here. You should define a byte (preferably one that won’t occur in the data) to indicate “start”, and then you have three choices:

    • follow the start byte with a “length” byte indicating how much data
      to read
    • define an “end” byte that marks the end of your data
    • read data until you have a complete message that matches one of
      the ones you expect

    The third option is the least extensible and flexible, of course, as if you already have a message “OPEN” you can’t then add a new message “OPENED” for instance.

    If you take the second option and define an “end” byte then you need to worry about escaping that byte if it occurs within your data (or use another byte that is guaranteed not to be in your data).

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

Sidebar

Related Questions

I have a simple Arduino sketch that spans several files. There is a function
I have an Arduino microcontroller listening on COM3. Using the arduino IDE and the
Have you used VS.NET Architect Edition's Application and System diagrams to start designing a
I have the following code on my Arduino that constantly checks for a serial
I have few projects ideas that involve plugging a computer or an arduino to
In an Arduino project, I have build configurations to compile for, and download to,
I have an Arduino-based device which connects through USB. I'd like to detect it
I have an Arduino with an Adafruit Motor Shield as part of my robot.
I have a Arduino app that needs to talk to my PC across the
I have a Python script that writes data packets to an Arduino board through

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.