[Vala] http server help



Hi,
I'm writing a little http server to send some binary data.

example:

void process_request (InputStream input, OutputStream output) throws Error {

    var file = File.new_for_path ("audio.mp3");
    var file_stream = file.read ();
    var data_stream = new DataInputStream (file_stream);
    data_stream.set_byte_order (DataStreamByteOrder.LITTLE_ENDIAN);
    uint8[] buffer = new uint8[5000000];
    data_stream.read (buffer);

    var header = new StringBuilder ();
    header.append ("HTTP/1.0 200 OK\r\n");
    header.append ("Content-Type: audio/mpeg\r\n");

    output.write (header.str.data);
    output.write(buffer);
    output.flush ();


}

int main () {
    try {
        var service = new SocketService ();
        service.add_inet_port (12345, null);
        service.start ();
        while (true) {
            var conn = service.accept (null);
            process_request (conn.input_stream, conn.output_stream);
        }
    } catch (Error e) {
        stderr.printf ("%s\n", e.message);
    }
    return 0;
}


but using firefox, when I save, the data do not arrive.
Why?

Thank you and good job.


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