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

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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T13:15:15+00:00 2026-05-26T13:15:15+00:00

I am new to C/C++. I am using the following code to send multiple

  • 0

I am new to C/C++. I am using the following code to send multiple messages to my server. A CONNECT message, a new line and then a null terminator. But when I send these messages, they are getting converted somewhere. I collected the messages exchanged using Wireshark. Because of the difference in what I am sending and what really got sent to the server, my server doesn’t respond well. Please help. Thank you.

C code (What I am trying to send):

    sockfd = socket(AF_INET, SOCK_STREAM, 0);
    char peer0_0[] = {0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x0d, 0x0a };
    char peer0_1[] = {0x0d, 0x0a }; //NEW LINE
    char peer0_2[] = {0x00, 0x0d, 0x0a }; //NULL TERM

    n = send(sockfd,peer0_0,strlen(peer0_0),0);
    n = send(sockfd,peer0_1,strlen(peer0_1),0);
    n = send(sockfd,peer0_2,strlen(peer0_2),0);

What I see in Wireshark (going to the server):

    char peer0_0[] = {0x43, 0x4f, 0x4e, 0x4e, 0x45, 0x43, 0x54, 0x0d, 0x0a };
    char peer0_1[] = {0x0d, 0x0a, 0xc3, 0x5f, 0xff, 0x7f };
  • 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-26T13:15:16+00:00Added an answer on May 26, 2026 at 1:15 pm

    You use strlen, but the arrays are not null terminated. Use sizeof:

    n = send(sockfd,peer0_0,sizeof(peer0_0),0);
    n = send(sockfd,peer0_1,sizeof(peer0_1),0);
    n = send(sockfd,peer0_2,sizeof(peer0_2),0);
    

    strlen is no good, as you have null terminator inside the third array (the first byte), so strlen(peer0_2) = 0.

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

Sidebar

Related Questions

I tried to send an email using the following code: MailMessage message = new
I am using the following code to send a sample message from the content
I have the following code: using (TcpClient client = new TcpClient()) { client.Connect(host, port);
I'm using the following code to send an sms. But this seems to not
I am Using Following Code for Send the Email from my application but problem
Using the following code: Private Sub MakeMeSomeXmlBeforeRyanGetsAngry() Dim db As New MyDBDataContext Dim customer
I'm using the following code (System.Data.SQLite within VB.net): Dim SQLconnect As New SQLite.SQLiteConnection() Dim
I am generating the scala AST using the following code: val setting = new
Assume the following code: using (SqlConnection conn = new SqlConnection(connectionString)) { ... using (SqlCommand
Given the following code: using (var client = new WebClient()) { string url =

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.