Page 1 of 1

Raw HTTP is bad for you? And whats with wxDebugReport?!

Posted: Sat Aug 13, 2005 1:49 pm
by lowjoel
I have almost gone INSANE using RAW HTTP for the last 2 hours... ARGH... I can barely connect to event my own local server (http://localhost) the following code is from my DevugReport::Process:

Code: Select all

	//Gather the data
	wxString str;
	for (size_t i = 0; i < GetFilesCount(); i++)
	{
		//Get the metadata
		wxString filename, desc, contents;
		GetFile(i, &filename, &desc);
		wxFileName fn(GetDirectory(), filename);
		
		//Then pluck the file
		wxFFile file(fn.GetFullPath());
		if (file.IsOpened() && file.ReadAll(&contents))
		{
			str += filename;
			str += "=";
			str += contents;
			str += "&";
		}
	}
	str = str.Mid(0, str.Length() - 1);
	
	//Connect to my server
	wxSocketClient client;
	wxIPV4address addr;
	addr.Hostname("localhost");
	addr.Service(80);
	client.Connect(addr, false);
	
	if (!client.WaitOnConnect(10))
	{
		die("Could not connect to server");
		return false;
	}
	
	client.Write("POST /bin/error.php HTTP/1.1\r\n", 128);
	client.Write("User-Agent: ClassTools/8\r\n", 128);
	client.Write("Content-Type: application/x-www-form-urlencoded\r\n\r\n", 128);
	client.Write("Host: localhost\r\n", 128);
	client.Write(str.ToAscii(), str.Length());
	client.Write("Connection: Close\r\n", 128);
	
	Reset();
	return true;
Any reason why it should always hang and 10 secs later report thatthey can't connect to the server?..

i put the Host: directive there... tried wityh and without... both still failed (it barely went past Connect()!)

btw, is there anything i should need to set for wxDebugReport? wxFFile file(fn.GetFullPath()); always can't find the file

Posted: Sat Aug 13, 2005 6:17 pm
by geon
Your app will wait for the socket to connect. By some unknown reason it fails, so after 10 seconds, it times out and continues executing.

Since you use a blocking connection method, you notice this as a "hang".

remove this:

Code: Select all

client.WaitOnConnect(10)
and move this to a wxSOCKET_LOST event handler:

Code: Select all

                die("Could not connect to server");
                return false;
also move this to a wxSOCKET_CONNECTION event handler:

Code: Select all

        client.Write("POST /bin/error.php HTTP/1.1\r\n", 128);
        client.Write("User-Agent: ClassTools/8\r\n", 128);
        client.Write("Content-Type: application/x-www-form-urlencoded\r\n\r\n", 128);
        client.Write("Host: localhost\r\n", 128);
        client.Write(str.ToAscii(), str.Length());
        client.Write("Connection: Close\r\n", 128);
       
        Reset();
        return true;

Are you using threads? it is a bit tricky together with sockets. There are some info on that topic if you search the forum.

Posted: Sat Aug 13, 2005 11:25 pm
by lowjoel
its in my crash report uploader.... i dont wanna package curl with my app

Posted: Mon Aug 15, 2005 5:40 pm
by Ryan Norton
lowjoel wrote:its in my crash report uploader.... i dont wanna package curl with my app
I don't see curl mentioned elsewhere here...

Posted: Mon Aug 15, 2005 10:20 pm
by lowjoel
wxDebugReportUpload...