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");
int(string)does stuff likeint('42') == 42, andint('-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
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.