Pinsickle
Pinsickle

Reputation: 633

'web browser' program works in Windows but not Linux

I am not going to post my code, it is for a school project and I don't want to risk having my code copied. That being said I don't expect an concrete answer but any thoughts would be appreciated.

Anyway, my assignment was as follows: I am suppose to simulate a web browser in the terminal. The user provides an IP address, file path and port number. I then have to create the get request send it to the server and parse the file's content length from the response. Finally I am to use the content length to count the bytes as I read in the file so I know when the read is complete. All of this data is to be written to an html file.

The weird part is I started working on this on my home machine (Linux) and was able to parse the content length and queue to the beginning of the html file and start reading. After after each read I subtract the number of bytes I read from the content length and when I zero out I haven't read the entire file. However, if I run this on one of the school machines (Windows using cygwin) it reads the entire file.

I've debugged using print statments and confirmed that I am parsing the content length correctly and the countdown is working also. It has me scratching my head. Any ideas?

Thanks

Upvotes: 0

Views: 288

Answers (2)

Michael Dillon
Michael Dillon

Reputation: 32392

Chances are that the stdio library that you are using on Windows does translations on any CR-LF combinations in the data. Check your compiler's manual for the open function and make sure that the mode is binary. This is a classical porting problem which requires different code to be compiled using ifdefs.

Check if your Windows compiler supports a constant like WIN32 which you can use like this

#if defined(WIN32)
   /* do this */
#else
   /* do that */
#endif

Upvotes: 0

Novikov
Novikov

Reputation: 4489

How do you determine that you haven't read the entire file? Are you relying on EOF? If so are you aware of HTTP/1.1 connection persistence?

Upvotes: 1

Related Questions