users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

handling mixed I/O.


From: Ferreira Maurizio
Subject: handling mixed I/O.
Date: Tue, 22 Apr 2008 11:43:29 +0200

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.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]