我对TCP套接字是个新手,我正在try 使用Python(服务器)来发送带有TCP套接字的编码图像(整数)的大小.使用C#WinForms应用程序(客户端)来接收这个整数,但是接收到的int看起来非常随机.例如,如果编码图像为6570
,则C#应用程序接收808924470
Python代码(发送方):
## Connection code...
# Send image size
imageSize = len(encodedImage)
socket.send(str(imageSize).encode("utf-8"))
C#代码(接收器):
// Connection code...
// Receive int
byte[] buffer = new byte[1024];
int bytesReceived = stream.Read(buffer);
int imageSize = BitConverter.ToInt32(buffer, 0);