gSoap 多线程实验报告( SOAP 协议栈的多线程实验报告)

 
gSoap 多线程实验报告
一、开发环境(客户端、服务器端均相同)
 
硬件环境:
AMD 3200+ 2.0G + 512M DDR + 10/100M 以太网卡
 
软件环境:
Operating System:Windows XP sp2
Compiler: Visual C++ 6.0
SOAP SDK: gSoap 2.7.9c
Multithread Library: pthread-2.5.0-win32-release
SSL Library: OpenSSL 0.9.7m
 
二、gSoap多线程程序的编写
2.1 服务器端程序的编写
 
对于服务器端,首先调用 soap_ssl_server_contex完成 SSL上下文环境的初始化,然后等待客户端发出服务请求。当主线程中检测到客户端发出新的SOAP请求时,调用 struct  soap *soap_copy(struct soap *soap) 函数创建新的soap 运行时环境(Runtime enviroment),新创建的 soap 与原先的soap runtime enviroment 是相互独立的,因此在多线程环境中各个线程可以独立处理 SOAP 请求而互不干涉。要在gSoap的服务器端支持OpenSSL,必须在调用 soap_accept后继续调用 soap_ssl_accept函数。在 soap_ssl_accept 验证后服务器和客户端建立安全的 SSL通道,然后主线程调用 pthread_create 创建新的线程来完成 SOAP服务。一个基本的服务器框架如下所示。
注意: 要在多线程的环境中使用 OpenSSL ,必须使用到这两个例程 CRYPTO_thread_setup() CRYPTO_thread_cleanup() 附录中给出了在 Win32 POSIX 的这两个例程的实现代码。
 
int  main()
{
   int m, s;
   pthread_t tid;
   struct soap soap, *tsoap;
   soap_ssl_init(); /* init OpenSSL (just once) */
/* Note: CRYPTO_thread_setup() must be called in multi-thread environment */
   if (CRYPTO_thread_setup())
   {
      fprintf(stderr, "Cannot setup thread mutex/n");
      exit(1);
   }
   soap_init(&soap);
   if (soap_ssl_server_context(&soap,
      SOAP_SSL_DEFAULT,
      "server.pem", /* keyfile: required when server must authenticate to clients (see SSL docs on how to obtain this file) */
      "password", /* password to read the key file */
      "cacert.pem", /* optional cacert file to store trusted certificates */
      NULL, /* optional capath to directory with trusted certificates */
      "dh512.pem", /* DH file, if NULL use RSA */
      NULL, /* if randfile!=NULL: use a file with random data to seed randomness */
      NULL /* optional server identification to enable SSL session cache (must be a unique name) */    ))
   {
      soap_print_fault(&soap, stderr);
      exit(1);
   }
   m = soap_bind(&soap, NULL, 18000, 100); // use port 18000
   if (m < 0)
   {
      soap_print_fault(&soap, stderr);
      exit(1);
   }
   fprintf(stderr, "Soc
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值