显示来自C ++嵌入式Web服务器的HTML图像 [英] displaying an HTML image from a C++ embeded web-server

查看:89
本文介绍了显示来自C ++嵌入式Web服务器的HTML图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,

我使用Snorkel API开发了一个嵌入式Web服务器(http://snorkelembedded.webs.com)
C ++中的
,以及基于客户端(浏览器)提交的信息生成QR码。



现在我正在尝试显示动态QR码(保存在.jpg中)文件)在客户端浏览器中,但它不起作用。 Snorkel嵌入式Web服务器基于在C ++代码中定义HTML代码,如下所示:



Hello,
I've developed an embedded web-server using "Snorkel API" (http://snorkelembedded.webs.com)
in C++, and generated a QR code based on information submitted from the client (browser).

Now I'm trying to display the dynamic QR code (which is saved in a .jpg file) in the client-browser, but it's not working. The Snorkel embedded web-server is based on defining the HTML code within the C++ code as follows:

#pragma hdrstop
#pragma argsused

#include <snorkel.h>
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>

call_status_t index_htm(snorkel_obj_t http,     /*read environment from this object */
			snorkel_obj_t outstream)  /* write data to the output stream   */
  {
   if (snorkel_printf (outstream,"<html><body><img src="QR4.jpg" alt="QR code" width=178 height=178</body></html>\r\n")== SNORKEL_ERROR)

		 return HTTP_ERROR;

   return HTTP_SUCCESS;
   }

void syntax (char *pszProg)
	{
	 fprintf (stderr, "syntax error:\n");
	 fprintf (stderr, "%s [-p <port>]\n", pszProg);
	 exit (1);
	 }

void main (int argc, char *argv[])
 {
  int i = 1;
  int port = 80;
  snorkel_obj_t http = 0;
  char szExit[10];
  for (; i < argc; i++)
  {
   if (argv[i][0] == '-' || argv[i][0] == '/')
	 {
	  char carg = argv[i][1];
	  switch (carg)
	   {
		case 'p':          /* port number */
		port = atoi (argv[i + 1]);
		i++;
		break;
		default:
		syntax (argv[0]);
		break;
		}
	  }
   }

/*
 *
 * initialize API
 *
 */
 if (snorkel_init () != SNORKEL_SUCCESS)
  {
	perror ("could not initialize snorkel\n");
	exit (1);
   }
/*
 *
 * create a server object
 *
 */
 http = snorkel_obj_create (snorkel_obj_server, 2,     /* number of handler threads to create */
								 NULL       /* directory containing index.html     */);

  if (!http)
   {
	 perror ("could not create http server\n");
	 exit (1);
   }

/*
 *
 * create a listener
 *
 */
 if (snorkel_obj_set (http,    /* server object */
					  snorkel_attrib_listener, /* attribute   */
					  port,    /* port number */
					  0 /* SSL support */ )
					  != SNORKEL_SUCCESS)
	  {
	   fprintf (stderr, "could not create listener\n");
	   snorkel_obj_destroy (http);
	   exit (1);
	  }

 /*
  *
  * overload the URL index.html
  *
  */

 if (snorkel_obj_set (http,    /* server object */
					 snorkel_attrib_uri,      /* attribute type */
					 GET,     /* method */
					  "/index.html",   /* url */
					  contenttype_text, index_htm) != SNORKEL_SUCCESS)
		 {
		   perror ("could not overload index.html");
		   snorkel_obj_destroy (http);
		   exit (1);
		  }

 if (snorkel_obj_set(http, snorkel_attrib_ipvers, IPVERS_IPV4, SOCK_SET) != SNORKEL_SUCCESS)
		{
		  fprintf (stderr, "error could not set ip version\n");
		  exit (1);
		 }

 /*
  *
  * start the server
  *
  */
  fprintf (stderr, "\n\n[HTTP] starting embedded server\n");
  if (snorkel_obj_start (http) != SNORKEL_SUCCESS)
   {
	perror ("could not start server\n");
	snorkel_obj_destroy (http);
	exit (1);
	}

/*
 *
 * do something while server runs
 * as a separate thread
 *
 */
  fprintf (stderr, "\n[HTTP] started.\n\n"
					 "--hit enter to terminate--\n");
  fgets (szExit, sizeof (szExit), stdin);

  fprintf (stderr, "[HTTP] bye\n");

 /*
  *
  * graceful clean up
  *
  */
  snorkel_obj_destroy (http);
  exit (0);
  } 





我不知道,也许问题出在我写的HTML代码中。

一些身体pleeeeeeease可以帮助我,我正试图解决这个问题一个星期了。



最好的问候。

Rania



I don't know, maybe the problem is within the HTML code i'm writing.
Can some body pleeeeeeease help me, I'm trying to solve this problem for a week now.

Best Regards.
Rania

推荐答案

if you are still struggeling; try to work with following code snippet to write the image content(bytes) in the output stream;

<img src="QR4.jpg" alt="QR code" width="178" height="178">
//write the bytes from the image file
</img>


这篇关于显示来自C ++嵌入式Web服务器的HTML图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆