Example #1
0
/////////////////////////////////////////////////////
//WINHOLDEM RUNTIME ENTRY POINT
/////////////////////////////////////////////////////
OHUSER_API double process_message (const char* pmessage, const void* param) {
        if (pmessage==NULL) { return 0; }
        if (param==NULL) { return 0; }

        if (strcmp(pmessage,"state")==0) { 
                holdem_state *state = (holdem_state*) param;
				if (ClientStarted != true){ initClient(); }
			 return process_state( (holdem_state*)param ); 
        }

        if (strcmp(pmessage,"query")==0) { 
//              MessageBox(NULL, (LPCSTR) param, "query", MB_OK);
                return process_query( (const char*)param ); 
        }

		//pfgws is outdated now, use exportable functions like GetSymbolFromDll etc
        if (strcmp(pmessage,"pfgws")==0) {      
//              MessageBox(NULL, "pfgws", "MESSAGE", MB_OK);
                m_pget_winholdem_symbol = (pfgws_t)param;
                return 0;
        }

        if (strcmp(pmessage,"event")==0 && strcmp((const char *) param, "load")==0) { 
			if (ClientStarted != true){ initClient(); }
//              MessageBox(NULL, "event-load", "MESSAGE", MB_OK);
        }

        if (strcmp(pmessage,"event")==0 && strcmp((const char *) param, "unload")==0) { 
//              MessageBox(NULL, "event-unload", "MESSAGE", MB_OK);
        }

        return 0;
}
Example #2
0
File: main.c Project: hluk/red
int main(int argc, const char *argv[])
{
    text[0] = '\0';

    if (argc == 2) {
        if (strcmp("-h", argv[1]) == 0 || strcmp("--help", argv[1]) == 0) {
            help(argv[0]);
            return EXIT_SUCCESS;
        } else if (strcmp("-t", argv[1]) == 0) {
            text[0] = '1';
        } else {
            int sock = initClient();
            sendMessage(sock, argv[1]);
            close(sock);
            return EXIT_SUCCESS;
        }
    } else if (argc > 2) {
        help(argv[0]);
        return EXIT_FAILURE;
    }

    int sock = initServer();
    pid_t pid = fork();
    if (pid == 0)
        processMessages(sock);
    close(sock);

    return pid >= 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}
Example #3
0
VRDeviceClient::VRDeviceClient(const Misc::ConfigurationFileSection& configFileSection)
	:pipe(Comm::TCPSocket(configFileSection.retrieveString("./serverName"),configFileSection.retrieveValue<int>("./serverPort"))),
	 active(false),streaming(false),
	 packetNotificationCB(0),packetNotificationCBData(0)
	{
	initClient();
	}
Example #4
0
VRDeviceClient::VRDeviceClient(const char* deviceServerName,int deviceServerPort)
	:pipe(Comm::TCPSocket(deviceServerName,deviceServerPort)),
	 active(false),streaming(false),
	 packetNotificationCB(0),packetNotificationCBData(0)
	{
	initClient();
	}
Example #5
0
// client main program
int main ( int argc, char *argv[] )
{
  client_param_t parameters =
  {
    NETWORK_DEFAULT_PORT,
    NETWORK_DEFAULT_HOST
  };
  args_param_t args_param_list[] =
  {
    { "-p",     &parameters.port, argsInteger },
    { "--port", &parameters.port, argsInteger },
    { "-h",     &parameters.host, argsString  },
    { "--host", &parameters.host, argsString  },
    { "-?",     NULL,             usage       },
    { "--help", NULL,             usage       },
    ARGS_DONE
  };
  int socketFile;

  // process command line arguments
  argsProcess ( argc, argv, args_param_list );
  printf ( "Port: %d\n", parameters.port );
  printf ( "Host: %s\n", parameters.host );

  // open socket
  socketFile = initClient ( parameters.port, parameters.host );

  // run service loop
  service ( socketFile );

  // clean up
  close ( socketFile );
  return 0;
}
Example #6
0
int writeServer(char *val)
{
	int fd, ret;
	char *cmd;

	initFiles();

	if (access(f_fpid, F_OK) || access(f_iput, F_OK)) {
		//printf("No Server; Start it with: "); 
		//printf("'Idestart <arguments>'");
		fflush(stdout);
		return QUIT;
	}
	initClient();

	cmd = (char *)malloc(strlen(val) + 2);
	sprintf(cmd, "%s\n", val);

	fd = open(f_iput, O_WRONLY | O_NONBLOCK);

	if (fd < 0) {
		usleep(100000);
		fd = open(f_iput, O_WRONLY | O_NONBLOCK);
		if (fd < 0) {
			//printf(" Server Does not Respond");
			return NRES;
		}
	}
	ret = write(fd, cmd, strlen(cmd) + 1);
	close(fd);
	freeNonzero(cmd);

	return waitOutput();
}
Example #7
0
int initialize(void)
{
    void *handle = PSIDplugin_getHandle("psaccount");

    /* init the logger */
    initLogger(NULL);

    /* set debug mask */
    // maskLogger(PSPMI_LOG_RECV | PSPMI_LOG_VERBOSE);

    /* initialize all modules */
    initSpawn();
    initForwarder();
    initClient();

    /* get psaccount function handles */
    if (!handle) {
	psAccountSwitchAccounting = NULL;
	mlog("%s: getting psaccount handle failed\n", __func__);
    } else {
	psAccountSwitchAccounting = dlsym(handle, "psAccountSwitchAccounting");
	if (!psAccountSwitchAccounting) {
	    mlog("%s: loading function psAccountSwitchAccounting() failed\n",
		 __func__);
	}
    }

    mlog("(%i) successfully started\n", version);

    return 0;
}
Example #8
0
int main(int argc, char** argv) {

    int status;
    char forking;
    message_t message;
    pid_t pid, cpid;
    ipc_t ipc;
    grid_t grid = gnew();
    
    LOGPID("Using IPC method: %s.\n", IPC_METHOD);
    
    /* Before doing anything else, map data should be loaded! */
    /* (so as to know the number of ants beforehand, at least */
    
	if((status = loadGrid(grid, "configurationFile")) != NO_ERRORS)
	{
		printf("An error occurred while loading the configuration file\n");
		exit(status);
	}
	
    /* This process will act as IPC server/simulation control */
    
    sid = 1;        /* Control has simulation ID 1 */
    pid = getpid(); /* and it's pid, obviously */

    LOGPID("Control process started.\n");    
    ipc = initServer();
    
    /* Good! IPC server working. Let's spawn those ants. */
    
    if (cpid = fork()) {
    
        /* Control code here */        
    	int aux;
    	if((aux = launchControl(ipc, grid)) != NO_ERROR){
    		printf("Simulation fail: %d\n", aux );
    	}else{
    		LOGPID("Simulation ended succesfully!\n");
    	}
    } else {       
    
        /* Ants here */
        do {
            sid++;
            pid = getpid();
            ipc = initClient();
            if (forking = (sid - 1 < grid->antsQuant))
                forking = ((cpid = fork()) == 0); /* Child will keep forking */
        } while (forking);
        
        /* We can do our own stuff now */                  
        status = antLoop(ipc, grid);
        exit(status);
        
    }
    
    freeGrid(grid);
}
string OAuthClient::request(){
	if(init) initClient(); else initialize();

	cout << "Requesting" << endl;
	string url = serverUrl + request_token_url;
	string queryString = getQuery(url, true);
	url = url + questionMark + queryString;

	string response = httpClient.get(url);

	Token response_token = Token::extract(response);
	initClient(response_token.key(), response_token.secret());

	response = serverUrl + authorize_url + questionMark + response;
	//authorize_url = response;
	cout << "response " + response<< endl;
	return response;
}
Example #10
0
File: main.c Project: adamjberg/VPN
void onClientStatusChanged(GtkWidget *widget, gpointer data)
{
    if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
    {
        initClient();
    }
    else
    {
        closeClient();
    }
}
Example #11
0
//-------------------------------------------------------------------------------------
void SpaceViewer::timeout()
{
	switch (updateType_)
	{
	case 0: // 初始化
		initClient();
		break;
	default: // 更新实体
		updateClient();
	};
}
Example #12
0
RmClient::RmClient( const char *serverName, const short portNumber )
{
	WORD wVersionRequested = MAKEWORD(1,1);
   	WSADATA wsaData;
    int nRet = WSAStartup(wVersionRequested, &wsaData);
	if (wsaData.wVersion != wVersionRequested)
	{	
		throw RmExceptions::SocketException( "RmServer::RmServer()", "Wrong version" );
	}
	
	initClient( serverName, portNumber );
}
Example #13
0
File: client.c Project: abalasu3/IP
int main(int argc,char *argv[]){

	char* PORTNO = "5540";
	char* SERVERIP = "127.0.0.1";

    //Populate the OS name
    if(uname(&sysname)){
        perror("Error obtaining os name");
        exit(-1);
    }
    
	hostname[511]='\0';
	gethostname(hostname,511);

	char *buf;
	int status,sockfd,numbytes;
	struct addrinfo hints,*res,*me;
	socklen_t addr_size;
	char s[INET6_ADDRSTRLEN];
	
	//Server details
	memset(&hints,0,sizeof(hints));
	hints.ai_family = AF_UNSPEC;
	hints.ai_socktype = SOCK_STREAM;
	
	getaddrinfo(SERVERIP,PORTNO,&hints,&res);
	
	//Create a socket
	if((sockfd = socket(res->ai_family,res->ai_socktype,res->ai_protocol)) == -1){
		perror("Server:socket creating error");
	}
	
	if(connect(sockfd,res->ai_addr,res->ai_addrlen) == -1){
		close(sockfd);
		perror("Client : Connect");
		exit(1);
	}
	
	inet_ntop(res->ai_family,get_in_addr((struct sockaddr *)res->ai_addr),s,sizeof(s));
	gethostname(hostname,1023);
	printf("Hostname : %s\n",hostname);
	printf("Client connecting to : %s\n",s);

    initClient(sockfd);
    
    sendLookup(sockfd,789);
    
    sendList(sockfd);
    
	close(sockfd);
    
	return 0;
}
Example #14
0
int startServer(char *val)
{
	int s_present = 0;
	initFiles();
	initClient();
	if (!strncmp(val, "-server", 7)) s_present = 1;
	if (!makeFifo()) {
		printf(" Could not create Fifo's");
		fflush(stdout);
		return QUIT;
	}
	execShellServ(val);
	if (s_present) return 0;
	return waitOutput();
}
Example #15
0
int startServer(char *val)
{
	int ret;
	initFiles();
	initClient();

	if (!makeFifo()) {
		printf(" Could not create Fifo's");
		fflush(stdout);
		return QUIT;
	}
	execShellServ(val);
	ret = waitOutput();
	return ret;
}
Example #16
0
/**
*函数介绍:构造函数
*输入参数:客户端名称:name,默认参数服务端ip:127.0.0.1,默认参数服务端端口:6666默认参数QObject *parent = 0
*返回值:无
*/
Network::Network(QString name, QString ip, int port, QObject *parent)
{
	this->clientName = name;
	this->remoteHostIp = ip;
	this->remoteHostPort = port;
	//初始化本地计算机信息
	initComputerInfo();
	//初始化客户端
	initClient();
	//初始化服务端
	initServer();

	//写入系统日志
	//Global::systemLog->append(QString(tr("初始化网络客户端:%1完毕.")).arg(clientName), QString(tr("初始化客户端:%1,并完成网络客户端与本地服务端程序相关联.")).arg(clientName), SystemLog::INFO);

}
Example #17
0
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	int osfhandle, sd;
	initClient(CLIENT_NAME, (argc == 2) ? argv[1] : SERVER_IPADDR, &osfhandle, &sd);

	int x1, y1, x2, y2, n;
	int map[1024];
	int stones[16384];

	while (ready(map, &x1, &y1, &x2, &y2, stones, &n)) {
		if (solver(map, x1, y1, x2+1, y2+1, stones, n) == EXIT_FAILURE) break;
	}

	finalClient(osfhandle, sd);
	return EXIT_SUCCESS;
}
/*Main Function
  Variable Definition:
  -- argc: the number of command arguments
  -- argv[]: each vairable of command arguments(argv[0] is the path of execution file forever)
  Return Value: client exit number
*/
int main(int argc, char *argv[]){
	//Test for correct number of arguments
	if (argc != 4){
		dieWithUserMessage("Parameter(s)", "<Server IP address/Name> <Server port/service> <Video file name>");
	}

	CLIENT_DATA		*cdata;			//_client_data structure node

	//Initialize GTK application
	gtk_init(&argc, &argv);

	//Allocate memory for _client_data structure
	cdata = g_malloc(sizeof(CLIENT_DATA));
	//Initialize _client_data structure
	cdata->host = argv[1];			//server ip address/name
	cdata->service = argv[2];		//server port/service
	cdata->video = argv[3];			//request video name

	//Create the main window
	cdata->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
	//Set the position of window
	gtk_window_set_position(GTK_WINDOW(cdata->window), GTK_WIN_POS_CENTER);
	//Set the default size of window
	gtk_window_set_default_size(GTK_WINDOW(cdata->window), WINDOW_LENGTH_SIZE, WINDOW_WIDTH_SIZE);
	//Set the icon of window
	gtk_window_set_icon(GTK_WINDOW(cdata->window), getIcon(VIDEO_ICON));
	//Set the title of window
	gtk_window_set_title(GTK_WINDOW(cdata->window), WINDOW_TITLE);

	//Initialize the menubar, toolbar, image, and button widget
	initClientLayout(cdata->window);
	//Initialize widget callback function
	initCallback(cdata);
	//Initalize video client global variables
	initClient(CLIENT_RTP_PORT);

	//Show everything in window
	gtk_widget_show_all(cdata->window);
	//Hide toolbar
	gtk_widget_hide(toolbar);

	//GTK application main function
	gtk_main();
	
	return 0;
}
	//CLIENT SETUP
	void TalkyBase::setup(string remoteHost, int remotePort)
	{
		if (nodeType != 0)
		{
			throw(string("Already initialised as node type ") + (nodeType==1 ? string("server") : string("client")));
			return;
		}
		
		
		_remoteHost = remoteHost;
		_remotePort = remotePort;
		
		initClient();
		beginThread();
		
		nodeType = 1;
		
	}
Example #20
0
struct _client *newClient(int sockfd){
    int i = 0;
    if(m_ClientManager.nClients >= MAX_CLIENTS){
        CLIENT_DEBUG("new a client failed1!");
        setErr(ERR_CLIENT_FULL);
        return 0;
    }
    for(i=0; i<MAX_CLIENTS; i++){
        if(!m_ClientManager.clients[i].used){
            initClient(&m_ClientManager.clients[i],sockfd);
            CLIENT_DEBUG("new a client ok!fd:%d\r\n",sockfd);
            return &m_ClientManager.clients[i];
        }
    }
    CLIENT_DEBUG("new a client failed!");
    setErr(ERR_CLIENT_FULL);
    return 0;
}
Example #21
0
/*----------------------------------------------------------------------------*/
int main(int argc, char *argv[])
{
	int osfhandle, sd;
	initClient(CLIENT_NAME, (argc == 2) ? argv[1] : SERVER_IPADDR, &osfhandle, &sd);

	global_memo = g_hash_table_new(g_str_hash, g_str_equal);	// 継続するならこの辺も考えないと
	//global_count = 0;

	int x1, y1, x2, y2, n;
	int map[1024];
	int stones[16384];

	while (ready(map, &x1, &y1, &x2, &y2, stones, &n)) {
		if (solver(map, x1, y1, x2+1, y2+1, stones, n) == EXIT_FAILURE) break;
	}

	finalClient(osfhandle, sd);
	return EXIT_SUCCESS;
}
Example #22
0
int DXDB_processCommand(redisClient *c) { //printf("DXDB_processCommand\n");
    if (c->http.mode == HTTP_MODE_ON) return continue_http_session(c);
    CLEAR_LUA_STACK
    server.alc.Operations++;
    server.alc.CurrClient  = c;
    server.alc.CurrCard    = 0;
    server.alc.CurrUpdated = 0;
    server.alc.lua_dirty   = 0;
    server.alc.CurrError   = NULL;//TODO if(CurrError) decrRefCount(CurError) ??
    initClient(c);
    sds arg0       = c->argv[0]->ptr;
    sds arg2       = c->argc > 2 ? c->argv[2]->ptr : NULL;
    if (c->argc == 3 /* FIRST LINE OF HTTP REQUEST */                     &&
        (!strcasecmp(arg0, "GET")      || !strcasecmp(arg0, "POST") ||
         !strcasecmp(arg0, "HEAD"))                                       &&
        (!strcasecmp(arg2, "HTTP/1.0") || !strcasecmp(arg2, "HTTP/1.1")))
        return start_http_session(c);
    else return 0;
}
Example #23
0
void acceptClients(serv *server){
    int socket = server->socket;

    struct sockaddr_in clientAddr;
    int clientSocket;

    pthread_attr_t worker_attr;
    pthread_attr_init(&worker_attr);
    pthread_attr_setdetachstate(&worker_attr, PTHREAD_CREATE_DETACHED);
    pthread_t worker_thread;

    socklen_t sinSizeClient = sizeof(struct sockaddr_in);

    /*the accept loop*/
    while(1){
        if((clientSocket = accept(socket, (struct sockaddr *) &clientAddr, &sinSizeClient)) < 0){
            perror("ERROR: Could not accept client");
            continue;
        }

        /*resolve the clients host name*/
        bstring clientHostName = safe_BfromCstr("");
        int rc = getnameinfo((struct sockaddr *) &clientAddr, sinSizeClient,
                    charBuffromBstr(clientHostName), IRC_MAX_LEN+1, NULL, 0, 0);
        clientHostName->slen = strlen(charBuffromBstr(clientHostName));
        if (rc != 0 || !clientHostName->slen){
            bdestroy(clientHostName);
            clientHostName = safe_BfromCstr("unresolved");
        }
        /*init the client*/
        cli *newClient = initClient(clientSocket, clientHostName, server);
        /*create thread to wait for the client to register and then handle client request*/
        if (pthread_create(&worker_thread, &worker_attr, &enterRegister, newClient) != 0){
            clientFree(newClient);
            close(socket);
            errnoExit("ERROR: Could not create thread");
        }
    }

    /*free server*/
    serverFree(server);
}
string OAuthClient::access(){
	string url = serverUrl + access_token_url;
	cout << "accessing" << endl;
	string queryString = getQuery(url);

	url = url + questionMark + queryString;
	cout << " url " + url<< endl;

	string response = httpClient.get(url, true);
	cout << "response " + response << endl;

	Token response_token = Token::extract(response);

	init = initClient(response_token.key(), response_token.secret());
	authenticated = authenticate();
	puserConfig.put("user.oauth_key", response_token.key());
	puserConfig.put("user.oauth_secret", response_token.secret());
	write_ini(uConfig, puserConfig);

	return response;
}
Example #25
0
int writeServer(char *val)
{
	int fd, fdt, tmp, ret, s_present = 0;
	char *cmd;

	initFiles();

	while(isblank(val[0])) val++;
	if (!strncmp(val, "-server", 7)) s_present = 1;

	if (access(f_fpid, F_OK) || access(f_iput, F_OK)) {
		printf("No Server; Start it with: "); 
		printf("'Idestart <arguments>'");
		fflush(stdout);
		return QUIT;
	}
	initClient();


	cmd = malloc(strlen(val) + 2);
	sprintf(cmd, "%s\n", val);

	fd = open(f_iput, O_WRONLY | O_NONBLOCK);

	if (fd < 0) {
		usleep(100000);
		fd = open(f_iput, O_WRONLY | O_NONBLOCK);
		if (fd < 0) {
			printf(" Server Does not Respond");
			fflush(stdout);
			return NRES ;
		}
	}
	ret = write(fd, cmd, strlen(cmd) + 1);
	close(fd);
	freeNonzero(cmd);

	if (s_present) return 0;
	return waitOutput();
}
Example #26
0
// add client to global clients array(g_clients)
// copy client
void addClient(TGClient * pClient)
{
	if(pClient==NULL)
	{
		return;
	}

	int count=CAL_CLIENT_ARRAY_SIZE; 

	TGClient * pT=NULL;
	initClient(&pT);
	memcpy(pT,pClient,sizeof(TGClient));
	

	int flag=0;
	int i=0;
	for(i=0;i<count;i++)
	{
		TGClient * pC=g_clients[i];
		if(pC==NULL)
		{
			g_clients[i]=pT;
			flag=1;
			break;
		}
	}

	if(!flag)
	{
		logN("CONTEXT",LOG_LEVEL_DEBUG,"start create client");
		int currentPos=clients_ar_size;
		appendClient();
		g_clients[currentPos]=pT;
	}
	// record current client connection counts	
	g_context->curClientCounts++;

}
bool OAuthClient::initialize(){
	cout << "Initialize" << endl;
	if(consumer!=0) {delete consumer;	consumer = NULL;}
	if(client!=0) {delete client;	client = NULL;}

	//Get the Consumer Key and Secret from Evimed config
	consumerKey = pevimedConfig.get<string>("evimed.consumerKey");
	consumerSecret = pevimedConfig.get<string>("evimed.consumerSecret");
	consumer = new Consumer(consumerKey, consumerSecret);

	//Try to get the OAuth key and secret from User config
	oauth_key = puserConfig.get<string>("user.oauth_key", "");
	oauth_secret = puserConfig.get<string>("user.oauth_secret", "");
	//Try to get User Information
	emailAddress = puserConfig.get<string>("user.emailAddress", "");

	if(initClient(oauth_key, oauth_secret)) {
		authenticated = authenticate();
		return true;
	}

	return false;
}
Example #28
0
void SignalProxy::setProxyMode(ProxyMode mode) {
  PeerHash::iterator peer = _peers.begin();
  while(peer != _peers.end()) {
    if((*peer)->type() != AbstractPeer::IODevicePeer) {
      IODevicePeer *ioPeer = static_cast<IODevicePeer *>(*peer);
      if(ioPeer->isOpen()) {
	qWarning() << "SignalProxy: Cannot change proxy mode while connected";
	return;
      }
    }
    if((*peer)->type() != AbstractPeer::SignalProxyPeer) {
      qWarning() << "SignalProxy: Cannot change proxy mode while connected to another internal SignalProxy";
      return;
    }
    peer++;
  }

  _proxyMode = mode;
  if(mode == Server)
    initServer();
  else
    initClient();
}
Example #29
0
double process_state( holdem_state* pstate ) {
        if (pstate!=NULL) { 
			// m_holdem_state[ (++m_ndx)&0xff ] = *pstate; }

			//_cprintf(", m_ndx&0xff);
			bool isErr;
			if( ClientStarted == false){
				initClient();
			}
			//GS_V[0]->printHoldemState(pstate);
			/*if( GS_V[0]->isTableSet == false ){				
				GS_V[0]->setTable(pstate,
					(int)GetSymbolFromDll(0,"nchairs",isErr),
					GetSymbolFromDll(0,"sblind",isErr),
					GetSymbolFromDll(0,"bblind",isErr),
					(int)GetSymbolFromDll(0,"userchair",isErr) );
			}
			
			GS_V[0]->processHoldemState(pstate);
			//GS_V[0]->liveCommentry();
		*/
		}
        return 0;
}
//######################################################################################################################
void* monitorCLIENT(void *argv)				//thread for client network
{
          set_global_var(mem_alloc());   //allocates the value to all the coins objects needed to store their attributes and all global variables and after that only global_var is used      
	initClient(((struct thread_data *) argv )-> args);
}