LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-29-2004, 06:31 PM   #16
lramos85
Member
 
Registered: Sep 2003
Location: Riverside, Ca
Distribution: Gentoo, FC3
Posts: 125

Rep: Reputation: 15

I'm having the same problem. I can't send images through the pipe, I have no Idea what I'm doing wrong, since it works on html files. This is that section of my code:

Code:
giffile = open(pch, O_RDONLY);
			hh << "HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: " << sizef << "\r\nContent-Type: image/gif\r\n\r\n";
			write(incomingsoc, (void *)hh.str().c_str(), hh.str().length());
			gifresult = read(giffile,(void*)getgif, 250);
			while (gifresult > 0) {
				write(incomingsoc,(void*)getgif,strlen(getgif));
				gifresult = read(giffile,(void*)getgif, 250);
			}
Please I would appreciate it. --LR
 
Old 11-29-2004, 10:32 PM   #17
lramos85
Member
 
Registered: Sep 2003
Location: Riverside, Ca
Distribution: Gentoo, FC3
Posts: 125

Rep: Reputation: 15
Oh, Nevermind How stupid of me, it was just a simple syntax problem.
 
Old 11-30-2004, 09:18 AM   #18
jnusa
Member
 
Registered: Jul 2004
Location: Denmark, Aarhus
Distribution: Ubuntu, Suse
Posts: 98

Rep: Reputation: 15
Iramos85, are you making the client side too? Still haven't figured out, how to read the images. Right now I'm trying to read one byte at a time, and save in a file. Works a little better, but not 100% yet.
The read_body function I use, reads text/html content 100% correct. The read size is the length of the content field. Whenever it tries to read an image/jpeg, the read function actually reads all the bytes, but in my buffer/file, there's only 4 bytes? As people already have said in this thread, it shouldn't matter what kind of data, you're reading, so my read_body function would work with images. Any suggestions?
 
Old 11-30-2004, 11:08 AM   #19
jnusa
Member
 
Registered: Jul 2004
Location: Denmark, Aarhus
Distribution: Ubuntu, Suse
Posts: 98

Rep: Reputation: 15
Here's the code segment for read_body(): It works beautifully with with text/html, but when I try images it writes about 4 bytes to the buffer... that's it! I've already read the header (and only the header), so only the body content resides. I could really use some help. The pointer ptr is allocated with the size of the body content, and null terminated.

Code:
int read_body(int fd, char *ptr, int length)
{	
	
	int	res = 0;
	int total = 0;
	
	if(ptr != NULL)
	{	//errno = 0;
		while(total < length )
		{	
			
			if((res = (read(fd, ptr + total, length))) < 0)
				errexit("\nError readback from server. Error: %s", strerror(errno));
			if(res >= 0)
				total += res;
			printf("\n Read: %d\tTotal read: %d\t Total length: %d\tfd: %d", res, total, length, fd);		
			if(res == 0)
			{	puts("\nBREAK 0!!!!");
				break;
			}
			if(res < 0)
			{	puts("\nBREAK -1!!!");
				break;
			}
		
		}
		
		logit(ptr, "temp.log");
		printf("\nRecieved:\n%s", ptr);

	}
	else 
		logit("\nEvt. malloc error -> no error handeling!", "system.log");	
	
	printf("\nSo far, so good!");
	return res;
}

Printout from terminal reading: http://www.leog.net/P1_logo.jpg

Code:
HTTP version: 1.1
Status-code: 200
length: 2876
strlen(obj->body_content): 2876
 Read: 2876     Total read: 2876         Total length: 2876     fd: 5
Recieved:
ÿØÿà
So far, so good!

Last edited by jnusa; 11-30-2004 at 11:19 AM.
 
Old 12-02-2004, 04:19 AM   #20
jnusa
Member
 
Registered: Jul 2004
Location: Denmark, Aarhus
Distribution: Ubuntu, Suse
Posts: 98

Rep: Reputation: 15
Just wanted to inform future developers about this bug.
The problem is, that there's a null terminator that seperates the image header and body, and when using C functions like strlen, write, puts ect, then you only get the image header... Geee took 2 weeks before I found out this problem . Solution: Simply do not use functions that terminate upon 0x00, and rely on the size you actually have read.
Regards Jnusa
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
http server help jrmontg Linux - Newbie 2 04-11-2005 01:49 PM
Two Apache http server problems... eyebrowsoffire Linux - Networking 2 02-17-2005 10:38 PM
Free / Cheap VirusScan Solution for Mail Server... Vince0000 Linux - General 3 08-18-2004 10:22 AM
Nice Cheap Dell Server box.... $350 Whitehat General 9 06-10-2003 10:43 PM
Linux email server and some HTTP server questions Steven6282 Linux - General 7 02-19-2003 03:39 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:24 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration