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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:55:56+00:00 2026-06-09T10:55:56+00:00

I need to send a integer from C# to Python over the network and

  • 0

I need to send a integer from C# to Python over the network and It hit me that if the “rules” are the same in both languages, and the bytesize of them are the same that should be the buffer size and i could just int(val) in Python… cant I?

Both have the size 32-bit, so in Python and C# I should be able to set

C#:

String str = ((int)(RobotCommands.standstill | RobotCommands.turncenter)).ToString();
Stream stream = client.GetStream();

ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(str);

stream.Write(ba, 0, 32);

Python:

while True:
    data = int( conn.recv(32) );

    print "received data:", data    

    if( (data & 0x8) == 0x8 ):
        print("STANDSTILL");

    if( (data & 0x20) == 0x20 ):
        print("MOVEBACKWARDS");
  • 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-09T10:55:59+00:00Added an answer on June 9, 2026 at 10:55 am
    data = int( conn.recv(32) );
    
    1. That is 32 bytes not 32 bits
    2. That is a maximum, you may get less then you request
    3. int(string) does stuff like int('42') == 42, and int('-56') == -56. That is it converts a human readable number into an int. But that’s not what you are dealing with here.

    You want to do something like this

    # see python's struct documentation, this defines the format of data you want
    data = struct.Struct('>i') 
    # this produces an object from the socket that acts more like a file
    socket_file = conn.makefile()
    # read the data and unpack it
    # NOTE: this will fail if the connection is lost midway through the bytes
    # dealing with that is left as an exercise to the reader
    value, = data.unpack(socket_file.read(data.size))
    

    EDIT

    It looks like you are also sending the data incorrectly in the C# code. I don’t know C#, so I can’t tell you how to do it correctly. Anybody who does, feel free to edit in the corrections.

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

Sidebar

Related Questions

I export functions from DLL and all of them need the same parameter (number
We need send h264 from flash to Wowza and after to vlc by RTSP
I need send certain attributes(say, human readable user name) from server to client after
I've a custom form (created with form API) that need send an uploaded file
I need to send an HTML report with images from an application. The report
I need to send some bytes over UDP Protocol the start squence is 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
I need to send some arguments from the iPhone to a php in the
I need to send emails from my web application (on account creation, password reset,
Background I have two services that need to communicate with each other over a
When I send a integer variable from one process to other through socket, and

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.