首先,如果有人想编译服务器并运行它问题用C编写的服务器显示BMP图像
我看着特别的功能是:
void serveHTML (int socket) {
char *message;
int i;
int j;
//image data
char bmpheader[54] = {0x42, 0x4D, 0x5A, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x00, 0x00, 0x00, 0x28, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x03, 0x00, 0x00, 0x00, 0x01, 0x00, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x13, 0x0B, 0x00, 0x00, 0x13, 0x0B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
char bmpimagedata[36] = {0x07, 0x07, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0x07, 0x07, 0x07, 0x07, 0x07, 0x66, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0x07, 0xFF, 0xFF, 0xFF, 0x46, 0x00, 0x00};
message = "HTTP/1.0 200 OK\r\n"
"Content-Type: image/bmp\r\n"
"Content-Length: 90\r\n";
printf ("%s\n", message);
write (socket, message, strlen(message));
// now send the contents of the web page to be displayed
i=0;
j=0;
while (i < 54) {
printf("%c", bmpheader[i]);
write (socket, &bmpheader[i], 1);
i++;
}
while (j < 36) {
printf("%c", bmpimagedata[j]);
write (socket, &bmpimagedata[j], 1);
j++;
}
}
我在这里所做的存储十六进制一个3x3的bmp文件的 数据分成两个 阵列(用于 修改的便利性)的头部和 图像数据。我尝试得到它 服务这个bmp在网络浏览器上。 但它失败。
我已经放置的printf的各地 地方打印的内容服务器 吐出......但是我想我 失去了一些东西(可能是 页脚?)。
任何帮助将不胜感激,我拉我的头发,为什么它不起作用。