|
|
|
|
||||||
| comp.protocols.tcp-ip TCP and IP network protocols. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello,
I have met very strange problem which is connected with HTTP protocol and getting image from some www site. I have written some HTTP client which is to connect to server and execute one GET command. I connect to www.google.pl throught my program and I use GET method to download its background. It seems that everything is <OK>, but when I try to open this .PNG file then every picture viewer program tell that it doesn't know format of this file. So, I downloaded some hex editor program to look at bytes in this file and compare this file to "the same" image downloaded thanks to browser. It appears that generally files are identical, but in many places I can see that bytes are different. What is reason of such weird problem? I hope that I write to appropriate discussion group. Wiktor |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On 26 Sep, 12:05, ope...@gmail.com wrote:
> Hello, > > I have met very strange problem which is connected with HTTP protocol > and getting image from some www site. > I have written some HTTP client which is to connect to server and > execute one GET command. > I connect towww.google.plthrought my program and I use GET method to > download its background. It seems that everything is <OK>, but when I > try to open this .PNG file then every picture viewer program tell that > it doesn't know format of this file. So, I downloaded some hex editor > program to look at bytes in this file and compare this file to "the > same" image downloaded thanks to browser. It appears that generally > files are identical, but in many places I can see that bytes are > different. What is reason of such weird problem? > > I hope that I write to appropriate discussion group. > > Wiktor The reason is simple - the difference in data handling between your client (> I have written some HTTP client which is to connect to server and execute one GET command) and default data handling of the browser. I am guessing your client is adding some data in the end of every packet it gets from the connection... |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On 26 Sep 2007, opexoc@gmail.com wrote:
> I have met very strange problem which is connected with HTTP > protocol and getting image from some www site. > I have written some HTTP client which is to connect to server and > execute one GET command. > I connect to www.google.pl throught my program and I use GET > method to download its background. It seems that everything is > <OK>, but when I try to open this .PNG file then every picture > viewer program tell that it doesn't know format of this file. So, > I downloaded some hex editor program to look at bytes in this file > and compare this file to "the same" image downloaded thanks to > browser. It appears that generally files are identical, but in > many places I can see that bytes are different. What is reason of > such weird problem? When your program writes the file to disk, do you by chance open the file in text mode (in C, fopen(filename, "w")) instead of binary mode (fopen(filename, "wb"))? This will likely result in a few altered bytes in the file on many systems. Make sure you're opening the file in binary mode. > I hope that I write to appropriate discussion group. Close enough ;-) Dave -- D.a.v.i.d T.i.k.t.i.n t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
On 26 Wrz, 18:12, David Tiktin <dtik...@nospam.totally-bogus.com>
wrote: > When your program writes the file to disk, do you by chance open the > file in text mode (in C, fopen(filename, "w")) instead of binary mode > (fopen(filename, "wb"))? This will likely result in a few altered > bytes in the file on many systems. Make sure you're opening the file > in binary mode. Hmm... I open file this way: ofstream out; out.open("myfile.txt", ios: ut);Can it be wrong way to open file? Wiktor |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
On 26 Wrz, 17:51, GArlington <garling...@tiscali.co.uk> wrote:
> The reason is simple - the difference in data handling between your > client (> I have written some HTTP client which is to connect to > server and execute one GET command) and default data handling of the > browser. I am guessing your client is adding some data in the end of > every packet it gets from the connection... This reason could be true, but I don't think so.Code which is to receive data looks: std::string Socket::ReceiveBytes() { std::string ret; char buf[1024]; while (1) { u_long arg = 0; if (ioctlsocket(s_, FIONREAD, &arg) != 0) break; if (arg == 0) break; if (arg > 1024) arg = 1024; int rv = recv (s_, buf, arg, 0); if (rv <= 0) break; std::string t; t.assign (buf, rv); ret += t; } return ret; } and that's all. Wiktor |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
>>> On 9/26/2007 at 1:59 PM, in message
<1190836789.443616.287990@r29g2000hsg.googlegroups .com>, <opexoc@gmail.com> wrote: > On 26 Wrz, 18:12, David Tiktin <dtik...@nospam.totally-bogus.com> > wrote: > >> When your program writes the file to disk, do you by chance open the >> file in text mode (in C, fopen(filename, "w")) instead of binary mode >> (fopen(filename, "wb"))? This will likely result in a few altered >> bytes in the file on many systems. Make sure you're opening the file >> in binary mode. > > Hmm... I open file this way: > > ofstream out; > out.open("myfile.txt", ios: ut);> > Can it be wrong way to open file? I don't (generally) use C++, but doing a Google search it looks like you might want to change the open to: out.open("myfile.txt", ios:binary | ios: ut);I assume it's not actually, in fact, a text file, since previously you mentioned it was a PNG file. |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
On 26 Wrz, 23:55, "Frank Swarbrick" <Frank.Swarbr...@efirstbank.com>
wrote: > I don't (generally) use C++, but doing a Google search it looks like you > might want to change the open to: > out.open("myfile.txt", ios:binary | ios: ut);> > I assume it's not actually, in fact, a text file, since previously you > mentioned it was a PNG file. It did , but not completely. Now ( and this is very weird ) every byte in myfile.txt which has 20h value in true file downloaded by browser in exactly the same location is 00h byte. Is it any good explanation for that? Wiktor |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
On 27 Sep 2007, opexoc@gmail.com wrote:
> On 26 Wrz, 23:55, "Frank Swarbrick" > <Frank.Swarbr...@efirstbank.com> wrote: > >> I don't (generally) use C++, but doing a Google search it looks >> like you might want to change the open to: >> out.open("myfile.txt", ios:binary | ios: ut);>> >> I assume it's not actually, in fact, a text file, since >> previously you mentioned it was a PNG file. > > It did , but not completely. Now ( and this is very weird ) > every byte in myfile.txt which has 20h value in true file > downloaded by browser in exactly the same location is 00h byte. Is > it any good explanation for that? You originally posted about a problem with a .png file. Was that solved by Frank's suggestion that you add ios:binary to the flags when you open the file? Can you now transfer .png files correctly? You switched to talking about a .txt file, which I take to mean an ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string character and 0x20 is the ASCII space character, so the values that are being converted don't seem just random, and could be related to handling the data as text elsewhere in your program. Have you done a capture of a download session using ethereal or wireshark to verify that the data coming over the line actually has the values you expect? How are you verifying the contents of the file? Why not hex dump the data as you receive it and see what you're actually reading off the socket? Dave -- D.a.v.i.d T.i.k.t.i.n t.i.k.t.i.n [at] a.d.v.a.n.c.e.d.r.e.l.a.y [dot] c.o.m |
|
|
|
#9 |
|
Messages: n/a
Hébergeur: |
On 27 Wrz, 18:26, David Tiktin <dtik...@nospam.totally-bogus.com>
wrote: > You switched to talking about a .txt file, which I take to mean an > ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string > character and 0x20 is the ASCII space character, so the values that > are being converted don't seem just random, and could be related to > handling the data as text elsewhere in your program. Ok. Problem have been solved. One thing should be changed - the name of file and that's it. out.open("myfile",ios::binary | ios: ut);No myfile.txt, but just myfile. Thanks! Wiktor |
|
|
|
#10 |
|
Messages: n/a
Hébergeur: |
In article <1190916472.243764.224160@k79g2000hse.googlegroups .com>,
opexoc@gmail.com wrote: > On 27 Wrz, 18:26, David Tiktin <dtik...@nospam.totally-bogus.com> > wrote: > > > You switched to talking about a .txt file, which I take to mean an > > ASCII text file. C and C++ use 0x00 (NUL) as the end-of-string > > character and 0x20 is the ASCII space character, so the values that > > are being converted don't seem just random, and could be related to > > handling the data as text elsewhere in your program. > > Ok. Problem have been solved. One thing should be changed - the name > of file and that's it. > > out.open("myfile",ios::binary | ios: ut);> No myfile.txt, but just myfile. If the filename suffix changes the behavior of your C++ library, I'd complain to your C++ vendor. -- Barry Margolin, barmar@alum.mit.edu Arlington, MA *** PLEASE post questions in newsgroups, not directly to me *** *** PLEASE don't copy me on replies, I'll read them in the group *** |
|
|
|
#11 |
|
Messages: n/a
Hébergeur: |
On 28 Wrz, 02:18, Barry Margolin <bar...@alum.mit.edu> wrote:
> If the filename suffix changes the behavior of your C++ library, I'd > complain to your C++ vendor. That's right. But, I can't change anything. Wiktor |
|
![]() |
| Outils de la discussion | |
|
|