Socket data download problem :S Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
Exor
Earned a small fee
Earned a small fee
Posts: 16
Joined: Sun Aug 30, 2009 3:56 pm

Socket data download problem :S

Post by Exor » Mon Oct 12, 2009 12:51 am

hi ! :)

i've got a problem when i download some info from socket.

i'm doing a browser client to download a file ... i send this to apache server: "GET / HTTP/1.1\nHost: site.com\r\n\r\n" and download starts.

i recieve 200 kb of data without problems, but after some seconds data will stir and it's a problem :S some pieces of old data stir with new data ... so i've a php file of 24 mb instead of 4 mb :S ..

Code: Select all

switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT : {
            buf = new wxChar [MAX_LENGTH];
            size = (MAX_LENGTH + 1) * sizeof(wxChar*);
            client->Read(buf,size);
            WxMemo1->AppendText(buf);
            break;
        }

Code: Select all

        const wxChar* msg;
        msg = "GET /onlygame/ HTTP/1.1\nHost: www.edenirc.net\r\n\r\n";
        int len = (wxStrlen(msg)+1)*sizeof(wxChar);
        client->Write(msg,len);
i hope u can help me :D

thanks

spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum » Mon Oct 12, 2009 1:44 pm

Hello,

i can't figure out exactly where is the problem, but i would try the following:

1) dont allocate a buffer everytime you receive a packet, but do it just once.
2) terminate to 0 after received it.
3) Append it to the previous data received.

something like (didn't check teh syntax, but should work):

Code: Select all


    static buf = new char[MAX_LENGTH];

    switch(event.GetSocketEvent())
    {
        case wxSOCKET_INPUT : {
            client->Read(buf,MAX_LENGTH);
            unsigned int in = client->LastCount();
            if(in>0) {
               buf [in]=0
               WxMemo1->AppendText(buf);
            }
            break;
        }
    }
bye
spectrum

Exor
Earned a small fee
Earned a small fee
Posts: 16
Joined: Sun Aug 30, 2009 3:56 pm

Post by Exor » Mon Oct 12, 2009 4:45 pm

thank you .. now it works :D

can u tell me a way to delete the header sent by apache ?

i tried to do so but it doesn't work

Code: Select all


bool inizia_copia = false;
      .
      .
      .
      .

       case wxSOCKET_INPUT : {
            client->Read(buf,MAX_LENGTH);
            unsigned int in = client->LastCount();
            if(in>0) {
                buf [in]=0;
                wxString comp;
                comp = buf;
                if (comp.Contains("\r\n\r\n"))
                    inizia_copia = true;
                if (inizia_copia) {
                    WxMemo1->AppendText(buf);
                    file->Write(buf,strlen(buf));
                }
            }
i tried to download an image but even if i delete the header from result file, for os it's not an image .. i believe that's a problem with ascii or unicode chars ...
is it possible ?

thanks ^^

spectrum
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 207
Joined: Sat Jul 21, 2007 12:17 pm

Post by spectrum » Mon Oct 12, 2009 8:58 pm

1) download all, is not garantee that \r\n\r\n is in the same packet.
2) wxString all=buf
3) on "all", do wxString::Find "\r\n\r\n"
4) on "all", do wxString::Remove ..
spectrum

Post Reply