简体   繁体   English

多个同时使用gsoap的客户端

[英]Multiple simultaneous clients with gsoap

I'm trying to enable multiple simultaneous client access to a webservice, enabeling a client to make a request and block until data is available (I am doing it this way since gsoap does not support notifications) 我试图使多个客户端同时访问Web服务,使客户端发出请求并阻塞直到数据可用(我这样做是因为gsoap不支持通知)

My webservice class is compiled with WITH_PURE_VIRTAL, meaning that I can't create instances of it, as it is an abstract class. 我的Web服务类是使用WITH_PURE_VIRTAL编译的,这意味着我无法创建它的实例,因为它是一个抽象类。 Thus, I use one class built by me, which inherits from the webservice class, and is responsible for managing the webservice and webclient requests. 因此,我使用一个由我构建的类,该类继承自webservice类,并负责管理webservice和webclient请求。

However, when my class is busy handling an existent client, I can't seem to receive any other requests. 但是,当我的班级忙于处理现有的客户端时,我似乎无法收到任何其他请求。

I read ( here ) that you should launch a thread with something similar to this: 我读过( 这里 ),您应该启动一个与此类似的线程:

   soap_serve((struct soap*)soap);
   soap_destroy((struct soap*)soap); // dealloc C++ data
   soap_end((struct soap*)soap); // dealloc data and clean up
   soap_done((struct soap*)soap); // detach soap struct
   free(soap); 

However, when I modify the that code to call my webservice class instead, the serve call doesn't do anything. 但是,当我修改该代码以改为调用Webservice类时,serve调用不会执行任何操作。

I also tried launching a new thread inside my webservice call methods, but as soon as the thread launches, the webclient receives an empty response. 我还尝试在webservice调用方法中启动新线程,但是一旦线程启动,webclient就会收到一个空响应。

Does anyone have any suggestions? 有没有人有什么建议?

If you look at my answer to this question you can see a very basic C++ threaded gSoap server. 如果您看一下我对这个问题的回答,您会看到一个非常基本的C ++线程gSoap服务器。 What I think you may be missing is the need to copy the service class, in my code the line tc = c.copy() ; // make a safe copy 我认为您可能缺少的是需要复制服务类,在我的代码行tc = c.copy() ; // make a safe copy tc = c.copy() ; // make a safe copy this copies the gSoap service instance including the gSoap context; tc = c.copy() ; // make a safe copy ,从而tc = c.copy() ; // make a safe copy包含gSoap上下文的gSoap服务实例; it's this copy that's passed into the new thread so that the new thread can respond to the request while the main thread waits for another request to be made. 就是将此副本传递到新线程中,以便新线程可以在主线程等待另一个请求发出时响应该请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM