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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:44:04+00:00 2026-06-09T05:44:04+00:00

I’m trying to get two systems to communicate, I want my C# application to

  • 0

I’m trying to get two systems to communicate, I want my C# application to talk trash with a TCP server written in Python.

First I thought of serialization, and got a good look at google’s protobuf. But don’t you only need serialization if you have complex types and datastructures. I don’t. I only want to send a enum (The default underlying type of the enumeration elements is int (Signed 32-bit integer).).

But the enum defined is rather large (C#):

[Flags]
public enum RobotCommands
{
    reset = 0x0,        // 0
    turncenter = 0x1,   // 1
    turnright = 0x2,    // 2
    turnleft = 0x4,     // 4
    standstill = 0x8,   // 8
    moveforward = 0x10, // 16
    movebackward = 0x20,// 32
    utility1on = 0x40,  // 64
    utility1off = 0x80, // 128
    utility2on = 0x100, // 256
    utility2off = 0x200 // 512
}

So really, do I need serialization? What’s the easiest way by Python to be able to read my enums that I send it?

I’ve tried just sending it as string, hoping to convert them back, but they seem to be string:

#!/usr/bin/env python

import socket

TCP_IP = '192.168.1.66'
TCP_PORT = 30000
BUFFER_SIZE = 20  # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()

print 'Connection address:', addr

while True:
    data = conn.recv(BUFFER_SIZE).encode("hex")
    print "received data:", data    

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

    if not data: break

    conn.send(data)

conn.close()
  • 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-09T05:44:05+00:00Added an answer on June 9, 2026 at 5:44 am

    Just passing the enum as string is OK. You can get them back to integer using int method.

    cmd = int(data);
    

    If you want hex version, using:

    cmd = hex(int(data))
    
    
    int(x[, base]) -> integer                                                                           
    
    Convert a string or number to an integer, if possible.  A floating point
    argument will be truncated towards zero (this does not include a string
    representation of a floating point number!)  When converting a string, use
    the optional base.  It is an error to supply a base when converting a
    non-string.  If base is zero, the proper base is guessed based on the
    string content.  If the argument is outside the integer range a
    long object will be returned instead.
    
    
    hex(number) -> string                                                                               
    
    Return the hexadecimal representation of an integer or long integer.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build

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.