Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/158.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
gSOAP C++;多线程独立服务器和客户端示例 我是GSOAP新手,可以在某个机构发布一个工作的GSOAP多线程C++独立服务器和客户端。在gSOAP文档中,多线程独立服务器没有关于在何处调用webservice函数的详细信息,例如int ns_add(int a,int b),没有对主服务器类-calc.cpp中头文件calc.h中定义的函数的调用_C++_Soap_Gsoap - Fatal编程技术网

gSOAP C++;多线程独立服务器和客户端示例 我是GSOAP新手,可以在某个机构发布一个工作的GSOAP多线程C++独立服务器和客户端。在gSOAP文档中,多线程独立服务器没有关于在何处调用webservice函数的详细信息,例如int ns_add(int a,int b),没有对主服务器类-calc.cpp中头文件calc.h中定义的函数的调用

gSOAP C++;多线程独立服务器和客户端示例 我是GSOAP新手,可以在某个机构发布一个工作的GSOAP多线程C++独立服务器和客户端。在gSOAP文档中,多线程独立服务器没有关于在何处调用webservice函数的详细信息,例如int ns_add(int a,int b),没有对主服务器类-calc.cpp中头文件calc.h中定义的函数的调用,c++,soap,gsoap,C++,Soap,Gsoap,请循序渐进地指导,这将有助于像我这样的新来者 你的回答会被赏识的。 < P>这是C++中的GSOAP的一个例子: 例如,在头文件中,我们有以下函数(服务): 在通过运行soapcpp2 interface.h生成存根之后 我们有一些文件,检查文档以了解它:soapStub.h、soapH.h、soapC.c、soapClient.c、soapServer.c 然后我们可以实现这样的服务: int main(int argc, char **argv) { int m, s; /* master

请循序渐进地指导,这将有助于像我这样的新来者


<>你的回答会被赏识的。

< P>这是C++中的GSOAP的一个例子: 例如,在头文件中,我们有以下函数(服务):

在通过运行soapcpp2 interface.h生成存根之后 我们有一些文件,检查文档以了解它:soapStub.h、soapH.h、soapC.c、soapClient.c、soapServer.c 然后我们可以实现这样的服务:

int main(int argc, char **argv)
{ int m, s; /* master and slave sockets */
struct soap soap;

soap_init(&soap);
load_list();
show_list();
if (argc < 2)
soap_serve(&soap);  /* serve as CGI application */
else
{ m = soap_bind(&soap, NULL, atoi(argv[1]), 100);
if (m < 0)
{ soap_print_fault(&soap, stderr);
  exit(-1);
}
fprintf(stderr, "Socket connection successful: master socket = %d\n", m);
for ( ; ; )
{ s = soap_accept(&soap);
  fprintf(stderr, "Socket connection successful: slave socket = %d\n", s);
  if (s < 0)
  { soap_print_fault(&soap, stderr);
    exit(1);
  } 
  soap_serve(&soap);
  soap_end(&soap);
  }
  }
  return 0;
  } 

 int yb__add_list(struct soap *soap, char *name, char *tel, char **result)
 {
 printf("the name is %s, tel is %s\n", name, tel);
 *result = (char *) soap_malloc(soap, 50);
 if(add_list(name, tel) > 0)
 strcpy(*result, "Success!");
 else
 strcpy(*result, "Failed!");
 show_list();
 save_list();
 return SOAP_OK;
 }
 int yb__del_list(struct soap *soap, int no, char **result)
 {
 *result = (char *) soap_malloc(soap, 50);
 if(delete_list(no) > 0)
 strcpy(*result, "Success!");
 else
 strcpy(*result, "Failed!");
 save_list();
 return SOAP_OK;
 }
 int yb__get_tel_by_name(struct soap *soap, char *name, char **result)
 {
 char tel[50];
 *result = (char *) soap_malloc(soap, 200);
 if(get_tel_by_name(name, tel ) == 1)
 sprintf(*result, "The tel of %s is: \n%s\nSuccess!", name, tel);
 else
 strcpy(*result, "Failed!");
 return SOAP_OK;
 }
 int yb__get_name_by_tel(struct soap *soap, char *tel, char **result)
 {
 char name[50];

 *result = (char *) soap_malloc(soap, 200);
 if(get_name_by_tel(tel, name) == 1)
 sprintf(*result, "The owner of %s is: \n%s\nSuccess!", tel, name);
 else
 strcpy(*result, "Failed!");
 return SOAP_OK;
 }
 int yb__get_list(struct soap *soap, char **result)
 {
 *result = (char *)malloc(1024);
 get_list(*result);
 return SOAP_OK;  
 }
int main(int argc,char**argv)
{int m,s;/*主插槽和从插槽*/
结构肥皂;
soap_init(&soap);
加载列表();
show_list();
如果(argc<2)
soap_serve(&soap);/*用作CGI应用程序*/
其他的
{m=soap_-bind(&soap,NULL,atoi(argv[1]),100);
if(m<0)
{soap_print_fault(&soap,stderr);
出口(-1);
}
fprintf(stderr,“套接字连接成功:主套接字=%d\n”,m);
对于(;;)
{s=soap\u accept(&soap);
fprintf(stderr,“套接字连接成功:从套接字=%d\n”,s);
如果(s<0)
{soap_print_fault(&soap,stderr);
出口(1);
} 
肥皂(和肥皂);
肥皂端(和肥皂);
}
}
返回0;
} 
int yb\u添加列表(结构soap*soap,字符*名称,字符*电话,字符**结果)
{
printf(“名称是%s,电话是%s\n”,名称,电话);
*结果=(char*)soap_malloc(soap,50);
如果(添加列表(姓名、电话)>0)
strcpy(*结果,“成功!”);
其他的
strcpy(*结果,“失败!”);
show_list();
保存列表();
返回SOAP_OK;
}
int-yb\uu del\u列表(结构soap*soap,int-no,char**result)
{
*结果=(char*)soap_malloc(soap,50);
如果(删除列表(否)>0)
strcpy(*结果,“成功!”);
其他的
strcpy(*结果,“失败!”);
保存列表();
返回SOAP_OK;
}
int yb\uu按名称获取电话(结构soap*soap,字符*名称,字符**结果)
{
电话[50];
*结果=(char*)soap_malloc(soap,200);
如果(按姓名获取电话)(姓名,电话)==1)
sprintf(*结果,“%s的电话是:\n%s\n成功!”,名称,电话);
其他的
strcpy(*结果,“失败!”);
返回SOAP_OK;
}
int yb\uu通过电话获取名称(结构soap*soap,字符*tel,字符**结果)
{
字符名[50];
*结果=(char*)soap_malloc(soap,200);
如果(通过电话获取姓名)(电话,姓名)==1)
sprintf(*结果,“%s的所有者是:\n%s\n成功!”,电话,姓名);
其他的
strcpy(*结果,“失败!”);
返回SOAP_OK;
}
int yb\uu get\u列表(结构soap*soap,字符**结果)
{
*结果=(char*)malloc(1024);
获取列表(*结果);
返回SOAP_OK;
}
您可以将服务作为终端中的单独服务器来执行。/server+端口 然后在客户端:

const char server[] = "localhost:8080/";
int executecmd(char *inbuf,  struct soap *p_soap);
int main(void)
{
struct soap soap;
char inbuf[MAX_CANON];
int ret;
soap_init(&soap);
for( ; ; ) {
fputs(NEWLINE_STRING, stdout);
fputs(CLIENT_PROMPT_STRING, stdout);
if (fgets(inbuf, MAX_CANON, stdin) == NULL)
  break;
if (*(inbuf + strlen(inbuf) - 1) == NEWLINE_SYMBOL)
  *(inbuf + strlen(inbuf) - 1) = 0;
if(is_blank_line(inbuf))
  continue;
if((ret = executecmd(inbuf, &soap)) < 0) 
  break; /* accept the quit command */
else if(ret == 0)
  continue; /* encount the error command */

}
return 1;
}

int executecmd(char *inbuf,  struct soap *p_soap)
{
char *result;
int n;
char **chargv;

if((n = makeargv(inbuf, BLANK_STRING, &chargv)) < 0){
printf("makeargv error\n");
exit(0);
}
if(!strcmp(chargv[0], "add") && n == 3){
soap_call_yb__add_list(p_soap, server, "", chargv[1], chargv[2], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "del") && n == 2 ){
soap_call_yb__del_list(p_soap, server, "", atoi(chargv[1]), &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "gettel") &&  n == 2){
soap_call_yb__get_tel_by_name(p_soap, server, "", chargv[1], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "getname") &&  n == 2){
soap_call_yb__get_name_by_tel(p_soap, server, "", chargv[1], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "list")){
soap_call_yb__get_list(p_soap, server, "", &result);
printf("%s\n", result);
return 0;   
}
else if(!strcmp(chargv[0], QUIT_STRING)){
return -1;
}
else if(!strcmp(chargv[0], HELP_STRING)){
printf("The usage of the command:\n");
printf("\"add name tel\"     add new entry to address book.\n");
printf("\"del no\"           delete entry by its corresponding phone number.\n");
printf("\"getname tel\"      get name by the corresponding phone number.\n");
printf("\"gettel name\"      get phone number by name.\n");
printf("\"list\"             list the current entries in the address book.\n");
printf("\"help\"             get help.\n");
printf("\"quit\"             quit this client.\n");
return 0;    
}
else{
printf("Can not execute this command.\n input \"help\" to get usage of commands.");
return 0;
}
return 1;
}
const char server[]=“localhost:8080/”;
int executecmd(char*inbuf,struct soap*p_soap);
内部主(空)
{
结构肥皂;
char inbuf[MAX_CANON];
int ret;
soap_init(&soap);
对于(;;){
FPUT(换行符字符串,标准输出);
FPUT(客户端提示字符串,标准输出);
如果(fgets(inbuf、MAX_CANON、stdin)=NULL)
打破
if(*(inbuf+strlen(inbuf)-1)=换行符)
*(inbuf+strlen(inbuf)-1)=0;
如果(是空白行(inbuf))
继续;
如果((ret=executecmd(inbuf和soap))<0)
break;/*接受quit命令*/
else if(ret==0)
继续;/*遇到错误命令*/
}
返回1;
}
int executecmd(char*inbuf,struct soap*p_soap)
{
字符*结果;
int n;
char**chargv;
if((n=makeargv(inbuf、空白字符串和chargv))<0){
printf(“makeargv错误\n”);
出口(0);
}
如果(!strcmp(chargv[0],“add”)&&n==3){
soap\u调用\u yb\u添加\u列表(p\u soap,服务器,“”,chargv[1],chargv[2],&result);
printf(“%s\n”,结果);
返回0;
}
否则如果(!strcmp(chargv[0],“del”)&&n==2){
soap_call_yb_del_list(p_soap,server,“”,atoi(chargv[1]),和result);
printf(“%s\n”,结果);
返回0;
}
else如果(!strcmp(chargv[0],“gettel”)&&n==2){
soap_call_yb___get_tel_by_name(p_soap,server,“”,chargv[1],&result);
printf(“%s\n”,结果);
返回0;
}
如果(!strcmp(chargv[0],“getname”)&&n==2,则为else{
soap\u call\u yb\u\u get\u name\u by\u tel(p\u soap,server,“”,chargv[1],&result);
printf(“%s\n”,结果);
返回0;
}
否则如果(!strcmp(chargv[0],“list”)){
soap\u调用\u yb\u获取\u列表(p\u soap、服务器、“,&result);
printf(“%s\n”,结果);
返回0;
}
否则如果(!strcmp(chargv[0],退出字符串)){
返回-1;
}
else if(!strcmp(chargv[0],HELP_字符串)){
printf(“命令的用法:\n”);
printf(“\”add name tel\”向通讯簿添加新条目。\n”);
printf(“\”del no\”通过相应的电话号码删除条目。\n”);
printf(“\”getname tel\”通过相应的电话号码获取姓名。\n”);
printf(“\”gettel name\”按名称获取电话号码。\n”);
printf(“列表”列出通讯簿中的当前条目。\n);
printf(“帮助”获取帮助。\n);
printf(“退出”退出此客户端。\n);
返回0;
}
否则{
printf(“无法执行此命令。\n输入\“help\”以获取命令的用法。”);
返回0;
}
返回1;
}

您也可以像这样在终端中运行客户端:./client

您可以在系统上安装gsoap的地方找到许多gsoap示例。在安装文件夹中可以找到一个“强”示例>文件夹,帮助您了解gSOAP的不同应用程序。< / P>参见C++多线程服务器示例的链接:如果您想要更好的答案,那么您需要自己做一些工作,您尝试过哪些代码?为什么不自己创建这样的指令呢?您好,我尝试了您发送的链接,但没有提到如何从void*process\ u请求(void*calc)提供ns\u add、ns\u mul。这就是为什么贴出这个问题。自己创建一个例子也是一个不错的选择,我会尝试
const char server[] = "localhost:8080/";
int executecmd(char *inbuf,  struct soap *p_soap);
int main(void)
{
struct soap soap;
char inbuf[MAX_CANON];
int ret;
soap_init(&soap);
for( ; ; ) {
fputs(NEWLINE_STRING, stdout);
fputs(CLIENT_PROMPT_STRING, stdout);
if (fgets(inbuf, MAX_CANON, stdin) == NULL)
  break;
if (*(inbuf + strlen(inbuf) - 1) == NEWLINE_SYMBOL)
  *(inbuf + strlen(inbuf) - 1) = 0;
if(is_blank_line(inbuf))
  continue;
if((ret = executecmd(inbuf, &soap)) < 0) 
  break; /* accept the quit command */
else if(ret == 0)
  continue; /* encount the error command */

}
return 1;
}

int executecmd(char *inbuf,  struct soap *p_soap)
{
char *result;
int n;
char **chargv;

if((n = makeargv(inbuf, BLANK_STRING, &chargv)) < 0){
printf("makeargv error\n");
exit(0);
}
if(!strcmp(chargv[0], "add") && n == 3){
soap_call_yb__add_list(p_soap, server, "", chargv[1], chargv[2], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "del") && n == 2 ){
soap_call_yb__del_list(p_soap, server, "", atoi(chargv[1]), &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "gettel") &&  n == 2){
soap_call_yb__get_tel_by_name(p_soap, server, "", chargv[1], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "getname") &&  n == 2){
soap_call_yb__get_name_by_tel(p_soap, server, "", chargv[1], &result);
printf("%s\n", result);
return 0;
}
else if(!strcmp(chargv[0], "list")){
soap_call_yb__get_list(p_soap, server, "", &result);
printf("%s\n", result);
return 0;   
}
else if(!strcmp(chargv[0], QUIT_STRING)){
return -1;
}
else if(!strcmp(chargv[0], HELP_STRING)){
printf("The usage of the command:\n");
printf("\"add name tel\"     add new entry to address book.\n");
printf("\"del no\"           delete entry by its corresponding phone number.\n");
printf("\"getname tel\"      get name by the corresponding phone number.\n");
printf("\"gettel name\"      get phone number by name.\n");
printf("\"list\"             list the current entries in the address book.\n");
printf("\"help\"             get help.\n");
printf("\"quit\"             quit this client.\n");
return 0;    
}
else{
printf("Can not execute this command.\n input \"help\" to get usage of commands.");
return 0;
}
return 1;
}