【发布时间】:2013-05-09 16:50:28
【问题描述】:
我无法将二进制数据接收到我的服务器 (python)。 似乎操作系统(WIN7)未经“许可”在多个数据包中发送大数据, 所以当我试图从我的客户端(C++)发送二进制数据时,我必须做一些操作来组合所有的数据。 我尝试了几种方法,但都没有奏效。
这里是发送部分(C++ - 工作正常):
sendbuf = "2011@" + ReadThisFile("C:\\0x3z4.jpg") + "@"; // buffer should be "2011@<Image Data>@"
// ReadThisFile returns string with binary data from file
vector<char> vect(sendbuf.begin(), sendbuf.end()); // Vector with the image data
iResult = send( ConnectSocket, &vect[0], vect.size(), 0 ); // Sending The Image
这里是接收部分(Python - 线程函数“处理程序”的一部分):
while True:
Buffer = Sock.recv(self.BufferSize)
if Buffer[0:4] == "2011":
self.Print(ADDR[0] + " > 2011 > Capture Screen Response.")
# Save Image
Path = datetime.now().strftime("Information\\" + ADDR[0] + "@" + self.Clients[Index].computerName + "\\CaptureScreen.Files\\" + "%d-%m-%Y-%H-%M-%S.png")
f = open(Path,'wb')
f.write(Buffer[5:-1])
data = ""
# I tried to receive data till i'll find the eof
while True:
data += Sock.recv(4096)
if data.find("EOF"):
break
f.write(data)
这个问题来自我和几个朋友为我们的课程工作的 Trojan 项目。 谢谢。
【问题讨论】:
-
对不起,你能改写吗?不是很清楚。
标签: c++ python sockets binary-data