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 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'm doing a system with Codeigniter , this is my first system with CI,
i'm trying to insert some data on a database using this code: -(void)insertLocationOnDatabase:(LocationType *)aLocation
i have function which is something like this function multiple_delete($entity1,$entity2,$entity2) { $query = SELECT
I'm developing a .NET Windows Forms application. I use the model-view-presenter design pattern, supervising
I now understand that a clustered index contains all of the row data, not
I have a question. Imagine you'd have an object you'd want to save in
I have a program to send mail using python smtplib. I have the mail
We are using sp's to convert a uploaded file into corresponding master values and
I am working on the Full Text Search in Sql Server 2005. I have
Is there an explanation of these statuses anywhere? http://dev.mysql.com/tech-resources/articles/using-new-query-profiler.html my specific question is in

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.