gsoap_gmtserver.cpp

Notes:

instructions

==================================================================
title   : aaa_currenttime.txt (gsoap currenttime demos)
edit    : 2021-12-14
author  : Neil Rieck
platform: Linux (CentOS-7.7) with gcc
purpose : steps to create currenttime gsoap server demo
ref1    : gsoapdoc283.pdf
ref2    : https://www.genivia.com/examples/time/index.html
legend  : ur (user response) is what you type
        : sr (system response) is what was displayed
notes   :
1) installed gsoap-2.8.16 via yum like so:
   yum install gsoap
2) gmtserver is run from Apache /cgi-bin (no plugin required)
3) gmtclient is only used to test gmtserver
==================================================================
ur: pwd
sr: /home/neil/gsoap_demos/currenttime

command-1
=========
#soapcpp2 -c -C    currentTime.h	# c-only, client-side only
soapcpp2     -C    currentTime.h	# both  , client-side only

command-2
=========
g++ -o gmtclient gmtclient.cpp soapC.cpp soapClient.cpp	\
-I/usr/include/ -lgsoap++ command-3 ========= soapcpp2 -S currentTime.h # both , server-side only command-4 ========= c++ -o gmtserver gmtserver.cpp soapC.cpp soapServer.cpp \
-I/usr/include/ -lgsoap++ command-5 ========= cp -p gmtserver /var/www/cgi-bin/ command-6 ========= ./gmtclient # test the client-side code

client code

// ====================================================================================
// title   : gmtclient.cpp
// ref1    : gsoapdoc283.pdf
// ref2    : https://www.genivia.com/examples/time/index.html
// platform: CentOS-7.7 with gcc 
// build   :
// 1) soapcpp2 -C currentTime.h
// 2) g++ -o gmtclient gmtclient.cpp soapC.cpp soapClient.cpp -I/usr/include/ -lgsoap++
// ====================================================================================
//
#include "soapH.h"
#include "currentTime.nsmap"
//
const char server1[] = "http://websrv.cs.fsu.edu/~engelen/gmtserver.cgi";
const char server2[] = "http://kawc4n.on.bell.ca/cgi-bin/gmtserver";
char server[255];
char buffer[255];
int choice;
int i;
//
//
//
int main() {
  time_t t;
  struct soap *soap = soap_new();
  //
  printf("menu:\n");
  printf("  1   %s\n", server1);
  printf("  2   %s\n", server2);
  printf("  other (free-form text)\n");
  printf("choice? (1,2,other) ");
  fgets(buffer, sizeof (buffer), stdin);
  for (i=0; sizeof (buffer); i++){
    if (buffer[i] == '\n'){
	buffer[i] = '\0';
	break;
    }
  }
  choice = strtol(buffer, NULL, 10);
  if (choice==1) {
    sprintf(server,"%s", server1);
  } else if (choice==2) {
    sprintf(server,"%s", server2);
  } else if (strlen(buffer)>10) {
    sprintf(server,"%s",choice);
  } else {
    printf("-w-bad choice or too short so exiting\n");
    exit(0);
  }
  printf("calling server: %s\n", server);
  soap_call_ns__currentTime(soap, server, "", &t);
  printf("Response: The current time is %s\n", ctime(&t));
  soap_destroy(soap);
  soap_end(soap);
  soap_free(soap);
  return 0;
}


server code

// ====================================================================================
// title   : gmtserver.cpp
// ref1    : gsoapdoc283.pdf
// ref2    : https://www.genivia.com/examples/time/index.html
// platform: CentOS-7.7 with gsoap installed via yum
// build   : CentOS-7.7 with gcc (gnu compiler collection)
// CLIENT
// 1) soapcpp2 -C currentTime.h
// 2) g++ -o gmtclient gmtclient.cpp soapC.cpp soapClient.cpp -I/usr/include/ -lgsoap++
// SERVER
// 1) soapcpp2 -S currentTime.h
// 2) c++ -o gmtserver gmtserver.cpp soapC.cpp soapServer.cpp -I/usr/include/ -lgsoap++
// ====================================================================================
#include "soapH.h"
#include "currentTime.nsmap"
int main() {
	  return soap_serve(soap_new());
}
int ns__currentTime(struct soap *soap, time_t *t) {
	  *t = time(0);
	  return SOAP_OK;
}  

left handBack to Linux Demo Index
home Back to Home
Neil Rieck
Waterloo, Ontario, Canada.