Ejemplo n.º 1
0
 int UDPSocket::open(const char * host, int port, bool client)
 {
   if(client)
     return openClient(host, port);
   else
     return openServer(host, port);    
 }
 bool open (const double newSampleRate, const BitArray& newChannels)
 {
     reservoirSize = 0;
     reservoirCapacity = 16384;
     reservoir.setSize (actualNumChannels * reservoirCapacity * sizeof (float));
     return openClient (newSampleRate, newChannels)
             && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioCaptureClient), (void**) &captureClient)));
 }
Ejemplo n.º 3
0
bool
CClientApp::startClient()
{
    double retryTime;
    CScreen* clientScreen = NULL;
    try {
        if (s_clientScreen == NULL) {
            clientScreen = openClientScreen();
            s_client     = openClient(args().m_name,
                                      *args().m_serverAddress, clientScreen);
            s_clientScreen  = clientScreen;
            LOG((CLOG_NOTE "started client"));
        }

#if SYSAPI_WIN32 && GAME_DEVICE_SUPPORT
        if (args().m_gameDevice)
        {
            // TODO: currently this is failing because we're not
            // forcing compile with the DX XInput.h (so the win
            // SDK is being used)... we need to figure out how to
            // tell cmake to prefer the DX include path.
            LOG((CLOG_DEBUG "installing xinput hook"));
            InstallXInputHook();
        }
#endif

        s_client->connect();
        updateStatus();
        return true;
    }
    catch (XScreenUnavailable& e) {
        LOG((CLOG_WARN "secondary screen unavailable: %s", e.what()));
        closeClientScreen(clientScreen);
        updateStatus(CString("secondary screen unavailable: ") + e.what());
        retryTime = e.getRetryTime();
    }
    catch (XScreenOpenFailure& e) {
        LOG((CLOG_CRIT "failed to start client: %s", e.what()));
        closeClientScreen(clientScreen);
        return false;
    }
    catch (XBase& e) {
        LOG((CLOG_CRIT "failed to start client: %s", e.what()));
        closeClientScreen(clientScreen);
        return false;
    }

    if (args().m_restartable) {
        scheduleClientRestart(retryTime);
        return true;
    }
    else {
        // don't try again
        return false;
    }
}
Ejemplo n.º 4
0
Archivo: client.c Proyecto: mannias/SO
int main() {
	openClient(0);
	clientRedirectionCreate(getpid());
	sendData(0, fillMessageData("client", "register", ""), sizeof(Message));
	clientRedirection(0, getpid());
	getResponce(0);
	while (1) {
		readConsole();
	}
	return 1;
}
Ejemplo n.º 5
0
bool
ClientApp::startClient()
{
	double retryTime;
	synergy::Screen* clientScreen = NULL;
	try {
		if (m_clientScreen == NULL) {
			clientScreen = openClientScreen();
			m_client     = openClient(args().m_name,
				*m_serverAddress, clientScreen);
			m_clientScreen  = clientScreen;
			LOG((CLOG_NOTE "started client"));
		}

		m_client->connect();

		updateStatus();
		return true;
	}
	catch (XScreenUnavailable& e) {
		LOG((CLOG_WARN "secondary screen unavailable: %s", e.what()));
		closeClientScreen(clientScreen);
		updateStatus(String("secondary screen unavailable: ") + e.what());
		retryTime = e.getRetryTime();
	}
	catch (XScreenOpenFailure& e) {
		LOG((CLOG_CRIT "failed to start client: %s", e.what()));
		closeClientScreen(clientScreen);
		return false;
	}
	catch (XBase& e) {
		LOG((CLOG_CRIT "failed to start client: %s", e.what()));
		closeClientScreen(clientScreen);
		return false;
	}

	if (args().m_restartable) {
		scheduleClientRestart(retryTime);
		return true;
	}
	else {
		// don't try again
		return false;
	}
}
Ejemplo n.º 6
0
static
bool
startClient()
{
	double retryTime;
	CScreen* clientScreen = NULL;
	try {
		if (s_clientScreen == NULL) {
			clientScreen = openClientScreen();
			s_client     = openClient(ARG->m_name,
							*ARG->m_serverAddress, clientScreen);
			s_clientScreen  = clientScreen;
			LOG((CLOG_NOTE "started client"));
		}
		s_client->connect();
		updateStatus();
		return true;
	}
	catch (XScreenUnavailable& e) {
		LOG((CLOG_WARN "cannot open secondary screen: %s", e.what()));
		closeClientScreen(clientScreen);
		updateStatus(CString("Cannot open secondary screen: ") + e.what());
		retryTime = e.getRetryTime();
	}
	catch (XScreenOpenFailure& e) {
		LOG((CLOG_CRIT "cannot open secondary screen: %s", e.what()));
		closeClientScreen(clientScreen);
		return false;
	}
	catch (XBase& e) {
		LOG((CLOG_CRIT "failed to start client: %s", e.what()));
		closeClientScreen(clientScreen);
		return false;
	}

	if (ARG->m_restartable) {
		scheduleClientRestart(retryTime);
		return true;
	}
	else {
		// don't try again
		return false;
	}
}
Ejemplo n.º 7
0
int coInitConnect()
{
    const char *envStr;
    char env[256], *portStr;
    float timeout;
    int32 handshake;
    int port;

    coSimLibData.soc = -1;

#if !(defined(WIN32) || defined(WIN64))
    /* we do our own handling of broken pipes */
    signal(SIGPIPE, SIG_IGN);
#endif

    /* get environment: if variable not set, exit with error-code */
    envStr = getenv("CO_SIMLIB_CONN");
    fprintf(stdout, "SIMLIB: %s\n", envStr);
    if ((!envStr) || (strlen(envStr) > 255))
        return -1;

    /* Client connection */
    strcpy(env, envStr);
    if (*env == 'C')
    {
        size_t retval;
        isServer = 0;
        /* get adress and port */
        portStr = strchr(env, '/');
        if (!portStr)
        {
            fprintf(stderr, "error parsing environment variable [%s]\n", env);
            return -1;
        }
        *portStr = '\0';
        portStr++;
        retval = sscanf(portStr, "%d_%f_%d", &minPort, &timeout, &coSimLibData.verbose);
        if (retval != 3)
        {
            fprintf(stderr, "coInitConnect: sscanf failed\n");
            return -1;
        }
        if (minPort < 1024 || minPort > 32767)
            return -1;

#ifndef WIN32
        if (!inet_aton(env + 2, &ip))
            return -1;
#else
        ip.s_addr = inet_addr(env + 2);
        if (ip.s_addr == -1)
            return -1;
#endif
        if (coSimLibData.verbose > 0)
            fprintf(stderr, " Starting Client to %s Port %d with %f sec timeout\n",
                    inet_ntoa(ip), minPort, timeout);

        /* we try to connect now */
        if ((port = openClient(ip.s_addr, minPort, timeout)) < 0)
            return -1;
    }

    /* Server connection */
    else if (*env == 'S')
    {
        size_t retval;
        isServer = 1;
        /* get adress and port */
        portStr = strchr(env, ':');
        if (!portStr)
        {
            fprintf(stderr, "error parsing environment variable [%s]\n", env);
            return -1;
        }
        *portStr = '\0';
        portStr++;
        retval = sscanf(portStr, "%d-%d_%f_%d", &minPort, &maxPort, &timeout, &coSimLibData.verbose);
        if (retval != 4)
        {
            fprintf(stderr, "coInitConnect: sscanf failed\n");
            return -1;
        }

        if (minPort < 1024 || minPort > 32767 || maxPort < 1024 || maxPort > 32767)
            return -1;

        /* we open and wait for the other side to connect */
        if ((port = openServer(minPort, maxPort)) < 0)
        {
            fprintf(stderr, "could not open server\n");
            return -1;
        }

        if (acceptServer(timeout) < 0)
        {
            fprintf(stderr, "could not accept server\n");
            return -1;
        }
    }
    /* Neither Client nor Server = ERROR */
    else
        return -1;

    /* Handshake: send 12345 to other side, so they might determine byte-swapping */
    handshake = 12345;
    sendData(&handshake, sizeof(int32));

#ifdef HAVE_GLOBUS
    {
        globus_result_t result = GLOBUS_SUCCESS;
        xsd_any *fault;
        int err, fault_type;
        fprintf(stderr, "activate globus modules\n");
        globus_module_activate(GLOBUS_COMMON_MODULE);
        globus_module_activate(GLOBUS_SOAP_MESSAGE_MODULE);
        registerSimulationType regSimulation;
        registerSimulationResponseType *regResponse;
        registerSimulationResponseType_init(&regResponse);
        globus_soap_message_attr_init(&message_attr);
        globus_soap_message_attr_set(message_attr, GLOBUS_SOAP_MESSAGE_AUTHZ_METHOD_KEY,
                                     NULL, NULL,
                                     (void *)GLOBUS_SOAP_MESSAGE_AUTHZ_HOST);
        globus_soap_message_attr_set(message_attr, GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_KEY,
                                     NULL, NULL,
                                     (void *)GLOBUS_SOAP_MESSAGE_AUTH_PROTECTION_PRIVACY);
        if ((result = SimulationService_client_init(&client_handle, message_attr, NULL)) == GLOBUS_SUCCESS)
        {
            char hostname[128];
            struct passwd *user = getpwuid(getuid());

            gethostname(hostname, 127);
            fprintf(stderr, "globus simulation client initialized\n");

            regSimulation.user = user->pw_name;
            regSimulation.host = hostname;
            regSimulation.port = port;
            regSimulation.name = "Fenfloss";
            fprintf(stderr, "globus regSimulation: [%s] [%s] [%d] [%s]\n", regSimulation.user, regSimulation.host, regSimulation.port, regSimulation.name);
            wsa_EndpointReferenceType_init(&epr);
            wsa_AttributedURI_init_contents(&epr->Address);
            xsd_anyURI_init_contents_cstr(&epr->Address.base_value,
                                          globus_common_create_string(getenv("GLOBUS_SIMULATIONSERVICE")));
            fprintf(stderr, " [%s]\n", getenv("GLOBUS_SIMULATIONSERVICE"));
            if ((err = SimulationPortType_registerSimulation_epr(client_handle,
                                                                 epr,
                                                                 &regSimulation,
                                                                 &regResponse,
                                                                 (SimulationPortType_registerSimulation_fault_t *)&fault_type,
                                                                 &fault)) == GLOBUS_SUCCESS)
            {
                SimulationType r = regResponse->result;

                simulationID = r.id;
            }
            else
            {
                fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
            }
        }
        else
        {
            fprintf(stderr, "globus error %d: [%s] \n", result, globus_object_printable_to_string(globus_error_get(result)));
        }
        registerSimulationResponseType_destroy(regResponse);
    }
#endif
    return 0;
}
Ejemplo n.º 8
0
int coAttach(void)
{
    int result;
    if (coSimLibData.soc == -1)
    {
        fprintf(stderr, "trying to reattach to covise...");
        if (isServer)
        {
            result = acceptServer(0.05f);
        }
        else
        {
            result = openClient(ip.s_addr, minPort, 1);
        }

        if (result != -1)
        {
            int32 handshake = 12345;
            fprintf(stderr, "attached\n");
            sendData(&handshake, sizeof(int32));

#ifdef HAVE_GLOBUS
            {
                xsd_any *fault;
                int err, fault_type;
                getSimulationType getSimulation;
                getSimulationResponseType *getResponse;
                getSimulationResponseType_init(&getResponse);

                getSimulation.user = getenv("USER");
                getSimulation.host = getenv("HOSTNAME");
                getSimulation.port = result;
                if ((err = SimulationPortType_getSimulation_epr(client_handle,
                                                                epr,
                                                                &getSimulation,
                                                                &getResponse,
                                                                (SimulationPortType_getSimulation_fault_t *)&fault_type,
                                                                &fault)) == GLOBUS_SUCCESS)
                {
                    if (getResponse != 0)
                    {
                        SimulationType sim = getResponse->result;

                        setStatusType setStatus;
                        setStatusResponseType *statusResponse;
                        setStatusResponseType_init(&statusResponse);

                        setStatus.user = sim.user;
                        setStatus.id = sim.id;
                        setStatus.status = 0; // attach

                        if ((err = SimulationPortType_setStatus_epr(client_handle,
                                                                    epr,
                                                                    &setStatus,
                                                                    &statusResponse,
                                                                    (SimulationPortType_setStatus_fault_t *)&fault_type,
                                                                    &fault)) == GLOBUS_SUCCESS)
                        {
                            fprintf(stderr, "globus set status: %d\n", statusResponse->result);
                        }
                        else
                        {
                            fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
                        }
                        setStatusResponseType_destroy(statusResponse);
                    }
                }
                else
                {
                    fprintf(stderr, "globus error %d: [%s] \n", err, globus_object_printable_to_string(globus_error_get(err)));
                }
                getSimulationResponseType_destroy(getResponse);
            }
#endif

            return 1;
        }
        else
        {
            fprintf(stderr, "failed\n");
        }
    }
    return 0;
}
Ejemplo n.º 9
0
int coInitConnect()
{
   const char *envStr;
   char env[256],*portStr;
   int minPort,maxPort;
   struct in_addr ip;
   float timeout;
   
   coSimLibData.soc = -1;
   
   /* we do our own handling of broken pipes */
   signal(SIGPIPE,SIG_IGN);
  
   /* get environment: if variable not set, exit with error-code */
   envStr=getenv("CO_SIMLIB_CONN");
   if ((!envStr)||(strlen(envStr)>255)) 
      return -1;
   
   /* Client connection */
   strcpy(env,envStr);
   if (*env=='C')
   {
      /* get adress and port */
      portStr  = strchr(env,'/');
      *portStr = '\0';
      portStr++;
      sscanf(portStr,"%d,%f,%d",&minPort,&timeout,&coSimLibData.verbose);
      if ( minPort<1024 || minPort>32767 )  return -1;
      if (!inet_aton(env+2,&ip)) return -1;
      
      if (coSimLibData.verbose>0)
         fprintf(stderr," Starting Client to %s Port %d with %f sec timeout\n",
                         inet_ntoa(ip),minPort,timeout);
      
      /* we try to connect now */
      if (openClient(ip.s_addr,minPort,timeout))
         return -1;
   }
   
   /* Server connection */
   else if (*env=='S')
   {
      /* get adress and port */
      portStr  = strchr(env,'/');
      *portStr = '\0';
      portStr++;
      sscanf(portStr,"%d-%d,%f,%d",&minPort,&maxPort,&timeout,&coSimLibData.verbose);
      if (    minPort<1024 || minPort>32767
           || maxPort<1024 || maxPort>32767 )  return -1;
      if (!inet_aton(env+2,&ip)) return -1;

      if (coSimLibData.verbose>0)
         fprintf(stderr," Starting Server to %s Port %d-%d with %f sec timeout\n",
                         inet_ntoa(ip),minPort,maxPort,timeout);
      
      /* we open and wait for the other side to connect */
      if ( openServer(minPort,maxPort) || acceptServer(timeout) )
         return -1;
      
   }
   
   /* Neither Client nor Server = ERROR */
   else
      return -1;
   
   return 0;
}
Ejemplo n.º 10
0
 bool open (const double newSampleRate, const BitArray& newChannels)
 {
     return openClient (newSampleRate, newChannels)
             && (numChannels == 0 || OK (client->GetService (__uuidof (IAudioRenderClient), (void**) &renderClient)));
 }