1
我需要通过网络发送一个从C#到Python的整数,它打击了我,如果两个语言的“规则”相同,并且它们的字节大小相同,应该是缓冲区大小,我可以int(val)
在Python中......我不能吗?C#和Python中的int是一样的吗?
双方都有大小为32位,所以在Python和C#我应该能够设置
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");
为什么不试试看看会发生什么? – 2012-08-05 13:06:08
@MichaelMauderer可能会出现一些不明确的情况,它会出错。我问这个问题没有问题。 – 2012-08-05 13:07:08
您的C#代码是否运行?你声称你的int的字符串表示有32个字节,这显然没有。 – CodesInChaos 2012-08-05 13:10:03