Jump to content

[SOLVED] Binary streams


photo

Recommended Posts

Hi,

 

I'm reading a packet of data from a socket and writing it to a file. But the data (image files) become corrupted when written to disk. I have opened the output as binary and have confirmed that "\n" in't getting translated in to "\r\n".

 

I am at a loss as to how to do this. We are using Unigine 2.3.1. Any ideas?

  void filewrite(Socket sock) {

    string filename = sock.readLine();
    filename = substr(filename, 0, strlen(filename) -1); // chop newline

    string size = sock.readLine();
    size = substr(size, 0, strlen(size));
    int filesize = int(size);

    File f = new File(engine.getDataPath() + filename , "wb");

    f.writeStream(sock, filesize);
    f.flush();
    f.close();

    sock.printf("WRITTEN\n");
  }
 
The data sent to the socket (using 'netcat') is in the format
 
filename\n
filesize\n
<binary data>
Link to comment

Hi Angus,

 

Not sure what is expected output and current output? You have stream with '/n' at the line endings and they are written to file. Why do you expect that they will be replaced to '/r/n'? Is there something that I missed?

Really small test sample will be very useful in this case.

 

Thanks!

How to submit a good bug report
---
FTP server for test scenes and user uploads:

Link to comment
×
×
  • Create New...