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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:30:49+00:00 2026-05-18T00:30:49+00:00

This is with regard to data sent over a socket to a C application

  • 0

This is with regard to data sent over a socket to a C application residing on a remote POS system.

Binary data is sent from a php application, in the C app packet structure there is 64bytes stored for a string e.g. a product name.

Now when I send the product name across network through php sockets, I use pack to convert data to binary

$value = 'product name' 
$qty = 2;
$len = strlen($value);
$output = '';
for($i=0; $i<$len; $i++) {
        $output .= pack('c', ord(substr($value, $i, 1))).pack('c',$qty) 
}

When the data is received by the C application the string contains a lot of garbage data, including numbers and special characters.

Which of the pack options i have to use to pack the product name into a 64byte binary string that will be interpreted by the C application in the correct format.

  • 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-18T00:30:50+00:00Added an answer on May 18, 2026 at 12:30 am

    Your loop to build $output produces a string like "p\x02r\x02o\x02d\x02u\x02c\x02t\x02 \x02n\x02a\x02m\x02e\x02"

    If your C program expects something like "product name\0\x02", then the loop should be:

    $output = '';
    for($i=0; $i<$len; $i++) {
            $output .= pack('c', ord(substr($value, $i, 1))); 
    }
    $output .= pack('c',0).pack('c',$qty);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a number of PHP scripts that pull data from my Facebook profile.
I have successfully sent (username/password) and received (true/false) values from my android app to
I'm scratching my head over this. I have a moderately successful app which has
In my application, I receive the image data from the server in a XML
I have few question in this regard When you create an internet page, does
Garbage Collection can become a time consuming process. In this regard, the GC tends
With regards this example from Code Complete: Comparison Compare(int value1, int value2) { if
I am have written a test console application for retrieving the data and sending
I have an application where i need to download a large amount of data
I have developed a core data model for my application. I need to display

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.