angus Posted October 20, 2016 Share Posted October 20, 2016 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
silent Posted October 20, 2016 Share Posted October 20, 2016 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: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
angus Posted October 24, 2016 Author Share Posted October 24, 2016 Hi Silent, This was my own poor coding and not Unigine, it seems. Sorry for the false alarm. Link to comment
Recommended Posts