Beispiel #1
0
void TCSoapThread(const std::string& host, uint16 port)
{
    struct soap soap;
    soap_init(&soap);
    soap_set_imode(&soap, SOAP_C_UTFSTRING);
    soap_set_omode(&soap, SOAP_C_UTFSTRING);

    // check every 3 seconds if world ended
    soap.accept_timeout = 3;
    soap.recv_timeout = 5;
    soap.send_timeout = 5;
    if (!soap_valid_socket(soap_bind(&soap, host.c_str(), port, 100)))
    {
        TC_LOG_ERROR("network.soap", "Couldn't bind to %s:%d", host.c_str(), port);
        exit(-1);
    }

    TC_LOG_INFO("network.soap", "Bound to http://%s:%d", host.c_str(), port);

    while (!World::IsStopped())
    {
        if (!soap_valid_socket(soap_accept(&soap)))
            continue;   // ran into an accept timeout

        TC_LOG_DEBUG("network.soap", "Accepted connection from IP=%d.%d.%d.%d", (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
        struct soap* thread_soap = soap_copy(&soap);// make a safe copy
        process_message(thread_soap);
    }

    soap_done(&soap);
}
Beispiel #2
0
int run_serve(int port)
{ struct soap *soap = soap_new1(SOAP_ENC_MTOM); /* enable MTOM */
  int ret;
  if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
    soap_print_fault(soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    soap->accept_timeout = 3600; /* let server time out after one hour */
    for (;;)
    { int sock = soap_accept(soap);
      if (!soap_valid_socket(sock))
      { if (soap->errnum)
          soap_print_fault(soap, stderr);
        else
          fprintf(stderr, "Server timed out\n");
        break;
      }
      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d... ", sock, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
      if (soap_serve(soap))
        soap_print_fault(soap, stderr);
      fprintf(stderr, "done\n");
      soap_destroy(soap);
      soap_end(soap);
    } 
  }
  ret = soap->error;
  soap_free(soap); /* done and free */
  return ret;
}
Beispiel #3
0
void TCSoapRunnable::run()
{
    struct soap soap;
    soap_init(&soap);
    soap_set_imode(&soap, SOAP_C_UTFSTRING);
    soap_set_omode(&soap, SOAP_C_UTFSTRING);

    // check every 3 seconds if world ended
    soap.accept_timeout = 3;
    soap.recv_timeout = 5;
    soap.send_timeout = 5;
    if (!soap_valid_socket(soap_bind(&soap, _host.c_str(), _port, 100)))
    {
        TC_LOG_ERROR("network.soap", "Couldn't bind to %s:%d", _host.c_str(), _port);
        exit(-1);
    }

    TC_LOG_INFO("network.soap", "Bound to http://%s:%d", _host.c_str(), _port);

    while (!World::IsStopped())
    {
        if (!soap_valid_socket(soap_accept(&soap)))
            continue;   // ran into an accept timeout

        TC_LOG_DEBUG("network.soap", "Accepted connection from IP=%d.%d.%d.%d", (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
        struct soap* thread_soap = soap_copy(&soap);// make a safe copy

        ACE_Message_Block* mb = new ACE_Message_Block(sizeof(struct soap*));
        ACE_OS::memcpy(mb->wr_ptr(), &thread_soap, sizeof(struct soap*));
        process_message(mb);
    }

    soap_done(&soap);
}
void LoginRESTService::Run()
{
    soap soapServer(SOAP_C_UTFSTRING, SOAP_C_UTFSTRING);

    // check every 3 seconds if world ended
    soapServer.accept_timeout = 3;
    soapServer.recv_timeout = 5;
    soapServer.send_timeout = 5;
    if (!soap_valid_socket(soap_bind(&soapServer, _bindIP.c_str(), _port, 100)))
    {
        TC_LOG_ERROR("server.rest", "Couldn't bind to %s:%d", _bindIP.c_str(), _port);
        return;
    }

    TC_LOG_INFO("server.rest", "Login service bound to http://%s:%d", _bindIP.c_str(), _port);

    http_post_handlers handlers[] =
    {
        { "application/json;charset=utf-8", handle_post_plugin },
        { "application/json", handle_post_plugin },
        { nullptr, nullptr }
    };

    soap_register_plugin_arg(&soapServer, &http_get, (void*)&handle_get_plugin);
    soap_register_plugin_arg(&soapServer, &http_post, handlers);
    soap_register_plugin_arg(&soapServer, &ContentTypePlugin::Init, (void*)"application/json;charset=utf-8");

    // Use our already ready ssl context
    soapServer.ctx = Battlenet::SslContext::instance().native_handle();
    soapServer.ssl_flags = SOAP_SSL_RSA;

    while (!_stopped)
    {
        if (!soap_valid_socket(soap_accept(&soapServer)))
            continue;   // ran into an accept timeout

        std::shared_ptr<soap> soapClient = std::make_shared<soap>(soapServer);
        boost::asio::ip::address_v4 address(soapClient->ip);
        if (soap_ssl_accept(soapClient.get()) != SOAP_OK)
        {
            TC_LOG_DEBUG("server.rest", "Failed SSL handshake from IP=%s", address.to_string().c_str());
            continue;
        }

        TC_LOG_DEBUG("server.rest", "Accepted connection from IP=%s", address.to_string().c_str());

        std::thread([soapClient]
        {
            soap_serve(soapClient.get());
        }).detach();
    }

    // and release the context handle here - soap does not own it so it should not free it on exit
    soapServer.ctx = nullptr;

    TC_LOG_INFO("server.rest", "Login service exiting...");
}
Beispiel #5
0
int calcService::run(int port)
{	if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				break;
			soap_destroy(this);
			soap_end(this);
		}
	}
	return this->error;
}
int PullPointSubscriptionBindingService::run(int port)
{	if (soap_valid_socket(this->soap->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				break;
			soap_destroy(this->soap);
			soap_end(this->soap);
		}
	}
	return this->soap->error;
}
int run_server(int port)
{ struct soap soap;
  int ret;
  /* Enable MTOM */
#ifdef WITH_GZIP
  soap_init1(&soap, SOAP_ENC_MTOM | SOAP_ENC_ZLIB); /* Enable MTOM */
#else
  soap_init1(&soap, SOAP_ENC_MTOM); 
#endif
  /* Set the MIME callbacks */
  soap.fmimereadopen = mime_read_open;
  soap.fmimereadclose = mime_read_close;
  soap.fmimeread = mime_read;
  soap.fmimewriteopen = mime_server_write_open;
  soap.fmimewriteclose = mime_server_write_close;
  soap.fmimewrite = mime_server_write;
  /* Bind socket */
  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))
    soap_print_fault(&soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    /* Optional: let server time out after one hour */
    soap.accept_timeout = 3600;
    /* Unix/Linux SIGPIPE, this is OS dependent:
    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this
    soap.socket_flags = MSG_NOSIGNAL;	// others need this
    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)
    */
    /* Server loop */
    for (;;)
    { int sock = soap_accept(&soap);
      if (!soap_valid_socket(sock))
      { if (soap.errnum)
          soap_print_fault(&soap, stderr);
        else
        { fprintf(stderr, "Server timed out (see code how to change this)\n");
          break;
        }
      }
      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d... ", sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
      if (soap_serve(&soap))
        soap_print_fault(&soap, stderr);
      fprintf(stderr, "done\n");
      soap_destroy(&soap);
      soap_end(&soap);
    } 
  }
  ret = soap.error;
  soap_destroy(&soap);
  soap_end(&soap);
  soap_done(&soap);
  return ret;
}
int BasicHttpBinding_USCOREICalculatorService::run(int port)
{   if (soap_valid_socket(this->soap->master) || soap_valid_socket(bind(NULL, port, 100)))
    {   for (;;)
        {   if (!soap_valid_socket(accept()) || serve())
                return this->soap->error;
            soap_destroy(this->soap);
            soap_end(this->soap);
        }
    }
    else
        return this->soap->error;
    return SOAP_OK;
}
int projectstatsService::run(int port)
{	if (soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				return this->error;
			soap_destroy(this);
			soap_end(this);
		}
	}
	else
		return this->error;
	return SOAP_OK;
}
int AmazonS3SoapBindingService::run(int port)
{	if (soap_valid_socket(this->soap->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				return this->soap->error;
			soap_destroy(this->soap);
			soap_end(this->soap);
		}
	}
	else
		return this->soap->error;
	return SOAP_OK;
}
int WSHttpBinding_USCOREINWNMasterServerAPIService::run(int port)
{	if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				return this->error;
			soap_destroy(this);
			soap_end(this);
		}
	}
	else
		return this->error;
	return SOAP_OK;
}
int videooverlayService::run(int port)
{	if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()) || serve())
				return this->error;
			soap_destroy(this);
			soap_end(this);
		}
	}
	else
		return this->error;
	return SOAP_OK;
}
int run_server(int port)
{ struct soap soap;
  int i, ret;
  /* Enable MTOM */
#ifdef WITH_GZIP
  soap_init1(&soap, SOAP_ENC_MTOM | SOAP_ENC_ZLIB); /* Enable MTOM */
#else
  soap_init1(&soap, SOAP_ENC_MTOM); 
#endif
  /* Set the MIME callbacks */
  soap.fmimereadopen = mime_read_open;
  soap.fmimereadclose = mime_read_close;
  soap.fmimeread = mime_read;
  soap.fmimewriteopen = mime_server_write_open;
  soap.fmimewriteclose = mime_server_write_close;
  soap.fmimewrite = mime_server_write;
  /* Bind socket */
  if (!soap_valid_socket(soap_bind(&soap, NULL, port, 100)))
    soap_print_fault(&soap, stderr);
  else
  { fprintf(stderr, "Bind to port %d successful\n", port);
    /* Optional: let server time out after one hour */
    soap.accept_timeout = 3600;
    /* Unix/Linux SIGPIPE, this is OS dependent:
    soap.accept_flags = SO_NOSIGPIPE;	// some systems like this
    soap.socket_flags = MSG_NOSIGNAL;	// others need this
    signal(SIGPIPE, sigpipe_handle);	// or a sigpipe handler (more portable)
    */
    /* Main thread spawns server threads */
    for (i = 1; ; i++)
    { struct soap *tsoap;
      pthread_t tid;
      int sock = soap_accept(&soap);
      if (!soap_valid_socket(sock))
      { if (soap.errnum)
          soap_print_fault(&soap, stderr);
        else
        { fprintf(stderr, "Server timed out (see code how to change this)\n");
          break;
        }
      }
      fprintf(stderr, "Thread %d accepts socket %d connection from IP %d.%d.%d.%d\n", i, sock, (int)(soap.ip>>24)&0xFF, (int)(soap.ip>>16)&0xFF, (int)(soap.ip>>8)&0xFF, (int)soap.ip&0xFF);
      /* Copy soap environment and spawn thread */
      tsoap = soap_copy(&soap);
      pthread_create(&tid, NULL, (void*(*)(void*))process_request, (void*)tsoap);
    } 
  }
  ret = soap.error;
  soap_done(&soap);
  return ret;
}
int ConsoleObserverService::run(int port)
{	if (soap_valid_socket(bind(NULL, port, 100)))
	{	for (;;)
		{	if (!soap_valid_socket(accept()))
				return this->error;
			(void)serve();
			soap_destroy(this);
			soap_end(this);
		}
	}
	else
		return this->error;
	return SOAP_OK;
}
Beispiel #15
0
//监听指定端口,事件参考event.c
//用于监听IPC上线或下线、或响应客户探测
//timeout设置超时时间,>0单位为秒 =0 用不超时 <0单位为微秒
static int listenPort(int port,int timeout)
{
	struct soap *serv = soap_new1(SOAP_IO_UDP); // to invoke messages
	int ret;
	//绑定端口号
	if (!soap_valid_socket(soap_bind(serv,NULL,port, 100)))
	{ 
		soap_print_fault(serv, stderr);
		printf("soap_bind error\n");
  		ret = -1;
		goto ERR0;
	}
	//加入多播地址
	struct ip_mreq mreq;
    mreq.imr_multiaddr.s_addr = inet_addr("239.255.255.250");
    mreq.imr_interface.s_addr = htonl(INADDR_ANY);
    if (setsockopt(serv->socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
    {
		printf("add multiaddr is error\n");
    	goto ERR0;
    }
	//监听
	ret = soap_wsdd_listen(serv,timeout);
	if(ret!=SOAP_OK)
	{
		soap_print_fault(serv, stderr);
		printf("soap_wsdd_listen error,ret=%d\n",ret);
		goto ERR0;
	}
	printf("soap_wsdd_listen return\n");
ERR0:
	soap_end(serv);
	soap_free(serv);
	return ret;
}
Beispiel #16
0
int main(int argc, char** argv)
{
	struct soap* serv = soap_new1(SOAP_IO_UDP | SOAP_IO_KEEPALIVE); 
	serv->bind_flags=SO_REUSEADDR;
	serv->connect_flags = SO_BROADCAST; 
	if (!soap_valid_socket(soap_bind(serv, NULL, port, 1000)))
	{
		soap_print_fault(serv, stderr);
		exit(1);
	}	

	ip_mreq mcast; 
	mcast.imr_multiaddr.s_addr = inet_addr(host);
	mcast.imr_interface.s_addr = htonl(INADDR_ANY);
	if (setsockopt(serv->master, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(mcast))<0) 
	{
		std::cout << "group membership failed:" << strerror(errno) << std::endl;		
	}	
	
	sendHello();
	mainloop(serv);

	signal(SIGINT, &sighandler);
	while (!stop)
	{
		mainloop(serv);
	}

	sendBye();
	mainloop(serv);

	return 0;
}
Beispiel #17
0
int Service::start(int port)
{
  if (!soap_valid_socket(bind(NULL, port, 100)))
  {
    soap_stream_fault(std::cerr);
    exit(1);
  }
  std::cerr << "Server Running" << std::endl;

  /* optional: set accept timeout to pulse acks every 500 ms, see below */
  soap->accept_timeout = -500000;

  for (;;)
  {
    if (soap_valid_socket(accept()))
    { 
      /* with iterative servers asynchronous messaging deadlock scenarios exist! */
      /* chain the WSRM service operations after the main service operations */
      if (soap_begin_serve(soap) == SOAP_OK)
        if (dispatch() == SOAP_NO_METHOD)
          soap_serve_request(soap);
      if (soap->error)
        soap_send_fault(soap);
      if (soap->error && soap->error != SOAP_STOP)
        soap_stream_fault(std::cerr);

      destroy();
      callback.destroy();

      soap_wsrm_dump(soap, stdout);
    }
    else
    {
      /* error or timeout? */
      if (soap->errnum)
      {
        soap_stream_fault(std::cerr);
        exit(1);
      }
      /* timeout occurs after 1 sec */
      /* send acks to peers (optional), 10 ms per message timeout */
      soap_wsrm_pulse(soap, -10000); /* 10 ms */
    }
  }
  return SOAP_OK;
}
Beispiel #18
0
int main()
{ struct soap soap;
  soap_init2(&soap, SOAP_IO_KEEPALIVE, SOAP_IO_KEEPALIVE | SOAP_XML_INDENT);
  /* Events A to C do not generate a response from the server */
  fprintf(stderr, "Client Sends Event: A\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_A))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  fprintf(stderr, "Client Sends Event: B\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_B))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  /* reset keep-alive when client needs to inform the server that it will close the connection. It may reconnect later */
  soap_clr_omode(&soap, SOAP_IO_KEEPALIVE);
  fprintf(stderr, "Client Sends Event: C\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_C))
    soap_print_fault(&soap, stderr);
  if (synchronous && soap_recv_empty_response(&soap))
    soap_print_fault(&soap, stderr);
  /* close the socket */
  soap_closesock(&soap);
  /* re-enable keep-alive which is required to accept and execute multiple receives */
  soap_set_omode(&soap, SOAP_IO_KEEPALIVE);
  /* Events Z generates a series of response from the server */
  fprintf(stderr, "Client Sends Event: Z\n");
  if (soap_send_ns__handle(&soap, event_handler_endpoint, event_handler_action, EVENT_Z))
    soap_print_fault(&soap, stderr);
  else
  { struct ns__handle response;
    for (;;)
    { if (!soap_valid_socket(soap.socket))
      { fprintf(stderr, "Connection was terminated (keep alive disabled?)\n");
        break;
      }
      if (soap_recv_ns__handle(&soap, &response))
      { if (soap.error == SOAP_EOF)
          fprintf(stderr, "Connection was gracefully closed by server\n");
        else
	  soap_print_fault(&soap, stderr);
	break;
      }
      else
      { switch (response.event)
        { case EVENT_A: fprintf(stderr, "Client Received Event: A\n"); break;
          case EVENT_B: fprintf(stderr, "Client Received Event: B\n"); break;
          case EVENT_C: fprintf(stderr, "Client Received Event: C\n"); break;
          case EVENT_Z: fprintf(stderr, "Client Received Event: Z\n"); break;
        }
      }
    }
  }
  soap_closesock(&soap); /* soap_send operations keep the socket open to possibly accept responses, so we need to explicitly close the socket now */
  soap_end(&soap); /* this will close the socket too (if keep alive is off), just in case */
  soap_done(&soap); /* detach environment (also closes sockets even with keep-alive) */
  return 0;
}
int OnvifRemoteDiscoveryBindingService::run(int port)
{
	if (soap_valid_socket(this->master) || bind(port))
	{
		for (;;)
		{
			if (!soap_valid_socket(accept()))
				return this->error;
			if (serve())
				return this->error;
			soap_destroy(this);
			soap_end(this);
		}
	}
	else {
		return this->error;
	}
	return SOAP_OK;
}
int main(int argc, char * argv[]) {
	SOAP_SOCKET m, s;
	struct soap soap;

	soap_init1(&soap, SOAP_IO_UDP);

	m = soap_bind(&soap, NULL,  PORT, 100);
 	/* reuse address */
 	soap.bind_flags = SO_REUSEADDR;
	if (!soap_valid_socket(m)) {
		soap_print_fault(&soap, stderr);
		exit(-1);
	}
	/* optionally join a multicast group */
	if (MULTICAST_GROUP) { 
		struct ip_mreq mreq;
		mreq.imr_multiaddr.s_addr = inet_addr(MULTICAST_GROUP);
		mreq.imr_interface.s_addr = htonl(INADDR_ANY);
		if (setsockopt(soap.socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
			printf("setsockopt failed\n");
	      		exit(-1);
		}
	}
	printf("socket bind success %d\n", m);
	for (;;) {
		printf("socket connect %d\n", s);
		s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			soap_print_fault(&soap, stderr);
			exit(-1);
		}
		if (soap_serve(&soap) != SOAP_OK) {
			soap_print_fault(&soap, stderr);
		}
		soap_destroy(&soap);
		soap_end(&soap);
		
	}

	soap_done(&soap);
	return 0;
}
Beispiel #21
0
int main(int argc, char **argv) {

	SOAP_SOCKET m, s; // master and slave sockets

	struct soap soap; // the gSOAP runtime context

	soap_init(&soap); // initialize the context (only once!)

	if (argc < 2) {
		soap_serve(&soap);	/* serve as CGI application */
	}
	else {

		int port=atoi(argv[1]);

		m = soap_bind(&soap, NULL, port, 100);

		if (!soap_valid_socket(m)) {
			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 (!soap_valid_socket(s))	{
				soap_print_fault(&soap, stderr);
				exit(-1);
			}

			soap_serve(&soap);
			soap_end(&soap);
		}
	}

	return 0;
}
Beispiel #22
0
int run_serve(int port)
{
  struct soap *soap = soap_new1(SOAP_XML_INDENT);
  int ret;

  if (soap_register_plugin(soap, http_da))
    exit(1);

  if (!soap_valid_socket(soap_bind(soap, NULL, port, 100)))
    soap_print_fault(soap, stderr);
  else
  {
    fprintf(stderr, "Bind to port %d successful\n", port);
    soap->accept_timeout = 3600; /* let server time out after one hour */
    for (;;)
    {
      SOAP_SOCKET sock = soap_accept(soap);
      if (!soap_valid_socket(sock))
      {
        if (soap->errnum)
          soap_print_fault(soap, stderr);
        else
        {
	  fprintf(stderr, "Server timed out\n");
          break;
        }
      }
      fprintf(stderr, "Accepting socket %d connection from IP %d.%d.%d.%d\n", sock, (int)(soap->ip>>24)&0xFF, (int)(soap->ip>>16)&0xFF, (int)(soap->ip>>8)&0xFF, (int)soap->ip&0xFF);
      if (soap_serve(soap))
        soap_print_fault(soap, stderr);
      fprintf(stderr, "Served\n\n");
      soap_destroy(soap);
      soap_end(soap);
    } 
  }
  ret = soap->error;
  soap_destroy(soap);
  soap_end(soap);
  soap_free(soap);
  return ret;
}
Beispiel #23
0
int BfcpService::run( int port )
{
  isRunning_ = true;
  char buf[1024];
  if (soap_valid_socket(this->master) || soap_valid_socket(bind(NULL, port, 100)))
  {	
    while (isRunning_)
    {
      if (!soap_valid_socket(accept()))
      {
        soap_sprint_fault(buf, sizeof buf);
        buf[sizeof(buf)-1] = '\0';
        LOG_WARN << buf;
        continue;
      }
      serve();
      soap_destroy(this);
      soap_end(this);
    }
  }
  return this->error;
}
int OnvifRemoteDiscoveryBindingService::bind(int port)
{
    int socket = RemoteDiscoveryBindingService::bind((const char*) NULL, port, 100);
    if (!soap_valid_socket(socket))
        return SOAP_INVALID_SOCKET;

    ip_mreq mcast;
    mcast.imr_multiaddr.s_addr = inet_addr(WSDD_MULTICAT_IP);
    mcast.imr_interface.s_addr = htonl(INADDR_ANY);
    if (setsockopt(socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mcast, sizeof(mcast)) < 0) {
        return SOAP_INVALID_SOCKET;
    }
    return socket;
}
Beispiel #25
0
int main(int argc, char **argv)
{ SOAP_SOCKET m, s; /* master and slave sockets */
  struct soap soap;
  soap_init(&soap);
  { m = soap_bind(&soap, NULL, 9999, 100);
    if (!soap_valid_socket(m))
    { 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 (!soap_valid_socket(s))
      { soap_print_fault(&soap, stderr);
        exit(-1);
      } 
      soap_serve(&soap);
      soap_end(&soap);
    }
  }
  return 0;
} 
Beispiel #26
0
int main(int argc, char * argv[]) {
	SOAP_SOCKET m, s;
	struct soap soap;

	soap_init1(&soap, SOAP_ENC_MTOM);


	m = soap_bind(&soap, NULL, PORT, 100);
	if (!soap_valid_socket(m)) {
		soap_print_fault(&soap, stderr);
		exit(-1);
	}

	printf("socket bind success %d\n", m);

	soap.fmimewriteopen = mime_server_write_open;
	soap.fmimewriteclose = mime_server_write_close;
	soap.fmimewrite = mime_server_write;

	for (;;) {
		printf("socket connect %d\n", s);
		s = soap_accept(&soap);
		if (!soap_valid_socket(s)) {
			soap_print_fault(&soap, stderr);
			exit(-1);
		}
		if (soap_serve(&soap) != SOAP_OK) {
			soap_print_fault(&soap, stderr);
		}
		soap_destroy(&soap);
		soap_end(&soap);

	}

	soap_done(&soap);
	return 0;
}
Beispiel #27
0
void *process_queue(void *soap)
{
    struct soap *tsoap = (struct soap*)soap;
    for (;;)
    {
        tsoap->socket = dequeue();
        if (!soap_valid_socket(tsoap->socket))
            break;
        soap_serve(tsoap);
        soap_destroy(tsoap);
        soap_end(tsoap);
        fprintf(stderr, "served\n");
    }
    return NULL;
}
Beispiel #28
0
void *callback_server(void *ctx)
{
  WSDualHttpBinding_USCOREICalculatorDuplexService *callback = (WSDualHttpBinding_USCOREICalculatorDuplexService*)ctx;
  THREAD_TYPE tid;

  callback->soap->accept_timeout = 10; /* server quits after 10 seconds of inactivity */

  printf("\n**** Callback Server Running\n");

  while (soap_valid_socket(callback->accept()))
    THREAD_CREATE(&tid, (void*(*)(void*))callback_thread, (void*)callback->copy());

  printf("\n**** Callback Server Terminated\n");

  return NULL;
}
Beispiel #29
0
int main()
{ struct soap soap;
  init_received();
  soap_init1(&soap, SOAP_IO_UDP);
  if (!soap_valid_socket(soap_bind(&soap, NULL, 10000, 100)))
  { soap_print_fault(&soap, stderr);
    exit(1);
  }
  for (;;)
  { printf("Accepting requests...\n");
    if (soap_serve(&soap))
      soap_print_fault(&soap, stderr);
    soap_destroy(&soap);
    soap_end(&soap);
  }
  soap_done(&soap);
  return 0;
}
Beispiel #30
0
//采用多播形式发送probe,立即返回不阻塞等待事件响应,获取事件响应要主动接下对应的sock或调用soap_wsdd_listen函数,事件参考event.c
//可以接收多个event,用于探测网络中存在的IPC
static int probeMulticast(const char *endpoint, const char * types, const char *scopes,int timeout)
{
	struct soap *serv = soap_new1(SOAP_IO_UDP); // to invoke messages
	int ret;
	const char *id = soap_wsa_rand_uuid(serv);
	
	ret = soap_wsdd_Probe(serv,
			  SOAP_WSDD_ADHOC,//SOAP_WSDD_ADHOC,	// ad-hoc mode
			  SOAP_WSDD_TO_TS,	// to a TS
			  endpoint, // address of TS; "soap.udp://239.255.255.250:3702"
			  id,	// message ID
			  NULL, // ReplyTo,表示回应的message ID,因为是主动回发起,所以没有,填NULL
			  types, //types,搜寻的设备类型"dn:NetworkVideoTransmitter tds:Device"
			  scopes,    //scopes,指定搜索范围,无填 NULL
			  NULL);   //match by,匹配规则,无填 NULL

	if(ret!=SOAP_OK)
	{
		soap_print_fault(serv, stderr);
		printf("soap_wsdd_Probe error,ret=%d\n",ret);
		goto ERR0;
	}	
	if (!soap_valid_socket(serv->socket))
	{ 
		soap_print_fault(serv, stderr);
		printf("sock is error\n");
  		ret = -1;
		goto ERR0;
	}
	serv->master = serv->socket;//必须指定,否则无法监听
	ret = soap_wsdd_listen(serv,timeout);
	
	if(ret!=SOAP_OK)
	{
		soap_print_fault(serv, stderr);
		printf("soap_wsdd_listen error,ret=%d\n",ret);
		goto ERR0;
	}
ERR0:
	soap_end(serv);
	soap_free(serv);
	return ret;
}