handling mixed I/O.

"Ferreira Maurizio" <[email protected]>
Newsgroups gmane.comp.gnu.prolog.general
Message-ID <[email protected]>
I need to do mixed (binary/text) output to a socket stream.
(I'm trying to develop a micro http server).

I tried he following code :

send_file(Sin,Sout,Size,Rcode,MimeType):-
    write(Sout,'HTTP/1.0 '), write(Sout,Rcode), write(Sout,'\r\n'),
    write(Sout,'Content-Type: '), write(Sout,MimeType),
write(Sout,'\r\n'),
    write(Sout,'Content-Length: '), write(Sout,Size),
write(Sout,'\r\n\r\n'),
    copy_file(Sin,Sout).

copy_file(Sin,_Sout):- at_end_of_stream(Sin),!.    
copy_file(Sin,Sout):- get_byte(Sin,C),put_byte(Sout,C),
copy_file(Sin,Sout).

The problem arises when I need to output binary data (images).
The trouble is that I dont' know how to set the Output stream type.
if it has the default value (type=Text), I cannot copy on it the binary
data,
and if I set it in binary mode, I cannot use 'write' to write to it.

Any suggetion ?

Regards.
Maurizio.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.