bool TCPSocket::connect(char* hostname, char* port) {
    if (endPoint != CLIENT)
        return false;

    SOCKET client;

    if (OpenClientSocket(&client, hostname, port, IPV4, TCP) == -1)
        return false;

    this->setFD(client);
}
Exemple #2
0
char *HTTP_Open(URL *Url)
{
 char *msg=NULL;
 char *proxy=NULL;
 char *server_host=NULL;
 int server_port=-1;

 /* Sort out the host. */

 if(!IsLocalNetHost(Url->host))
    proxy=ConfigStringURL(Proxies,Url);

 if(proxy)
   {
    if(proxyUrl)
       FreeURL(proxyUrl);
    proxyUrl=NULL;

    proxyUrl=CreateURL("http",proxy,"/",NULL,NULL,NULL);
    server_host=proxyUrl->host;
    server_port=proxyUrl->port;
   }
 else
   {
    server_host=Url->host;
    server_port=Url->port;
   }

 if(server_port==-1)
    server_port=DefaultPort(Url);

 /* Open the connection. */

 server=OpenClientSocket(server_host,server_port);

 if(server==-1)
    msg=GetPrintMessage(Warning,"Cannot open the HTTP connection to %s port %d; [%!s].",server_host,server_port);
 else
   {
    init_io(server);
    configure_io_timeout(server,ConfigInteger(SocketTimeout),ConfigInteger(SocketTimeout));
   }

 return(msg);
}
Exemple #3
0
/* ------------------------------- */
int main(int ac, char **av)
{
    int cc, i, t;
    int Debug = 0;
    char *tests = NULL;
    static char *vers = "AFP3.2";
    static char *uam = "Cleartxt Passwrd";
    struct passwd *pw = getpwuid(getuid());

    if (pw)
        User = strdup(pw->pw_name);

    while (( cc = getopt( ac, av, "t:vVgG345h:n:p:s:u:w:c:F:" )) != EOF ) {
        switch ( cc ) {
        case 't':
            tests = strdup(optarg);
            break;
        case '3':
            vers = "AFPX03";
            Version = 30;
            break;
        case '4':
            vers = "AFP3.1";
            Version = 31;
            break;
        case '5':
            vers = "AFP3.2";
            Version = 32;
            break;
        case 'n':
            Iterations = atoi(optarg);
            break;
        case 'h':
            Server = strdup(optarg);
            break;
        case 's':
            Vol = strdup(optarg);
            break;
        case 'u':
            if (User)
                free(User);
            User = strdup(optarg);
            break;
        case 'w':
            Password = strdup(optarg);
            break;
        case 'p' :
            Port = atoi( optarg );
            if (Port <= 0) {
                fprintf(stdout, "Bad port.\n");
                exit(1);
            }
            break;
        case 'v':
            Debug = 1;
            break;
        case 'V':
            Verbose = 1;
            break;
        case 'g':
            rwsize *= 10;
            break;
        case 'G':
            rwsize *= 100;
            break;
        case 'F':
            bigfilename = strdup(optarg);
            break;
        default :
            usage( av[ 0 ] );
        }
    }

    if (! Server)
        usage( av[ 0 ] );

    if (! Debug) {
        Verbose = 0;
        freopen("/dev/null", "w", stdout);
    }

    if ((User[0] == 0) || (Password[0] == 0))
        uam = "No User Authent";

    Iterations_save = Iterations;
    results = calloc(Iterations * NUMTESTS, sizeof(unsigned long));

    if (!tests) {
        memset(teststorun, 1, NUMTESTS);
    } else {
        i = 0;
        for (; tests[i]; i++) {
            t = tests[i] - '1';
            if ((t >= 0) && (t <= NUMTESTS))
                teststorun[t] = 1;
        }
        if (teststorun[TEST_READ100MB] && !bigfilename)
            teststorun[TEST_WRITE100MB] = 1;
        if (teststorun[TEST_ENUM2000FILES])
            teststorun[TEST_CREATE2000FILES] = 1;
    }

    if ((Conn = (CONN *)calloc(1, sizeof(CONN))) == NULL)
        return 1;

    Conn->type = Proto;
    if (!Proto) {
        int sock;
        dsi = &Conn->dsi;
        sock = OpenClientSocket(Server, Port);
        if ( sock < 0) {
            return 2;
        }
        dsi->protocol = DSI_TCPIP;
        dsi->socket = sock;
    }
    Conn->afp_version = Version;

    /* login */
    if (Version >= 30)
      	ExitCode = ntohs(FPopenLoginExt(Conn, vers, uam, User, Password));
    else
      	ExitCode = ntohs(FPopenLogin(Conn, vers, uam, User, Password));

    vol  = FPOpenVol(Conn, Vol);
    if (vol == 0xffff) {
        nottested();
    }

    int dir;
    char testdir[MAXPATHLEN];

    sprintf(testdir, "LanTest-%d", getpid());

    if (FPGetFileDirParams(Conn, vol, DIRDID_ROOT, "", 0, (1<< DIRPBIT_DID)))
        fatal_failed();

    if (is_there(Conn, DIRDID_ROOT, testdir) == AFP_OK)
        fatal_failed();

    if (!(dir = FPCreateDir(Conn, vol, DIRDID_ROOT, testdir)))
        fatal_failed();

    if (FPGetFileDirParams(Conn, vol, dir, "", 0 , (1<< DIRPBIT_DID)))
        fatal_failed();

    if (is_there(Conn, DIRDID_ROOT, testdir) != AFP_OK)
        fatal_failed();

    while (Iterations--) {
        run_test(dir);
    }

    FPDelete(Conn, vol, dir, "");

    if (ExitCode != AFP_OK && ! Debug) {
        if (!Debug)
            printf("Error, ExitCode: %u. Run with -v to see what went wrong.\n", ExitCode);
        goto exit;
    }

    displayresults();

exit:
    if (Conn) FPLogOut(Conn);

    return ExitCode;
}
/*
 * Application entry point.
 */
int main(int argc, char* argv[])
{
	char *ip = NULL;
	char *port = NULL;
	int iResult = 0;

	system("cls");

	// Check input arguments for IP and PORT and open client socket if required
	if (argc != 3)
	{
		printf("Usage: %s <IP> <PORT>\n", argv[0]);
		printf("EyeX data will not be streamed\n");
	}
	else
	{
		ip = argv[1];
		port = argv[2];
		printf("Trying connection with %s : %s\n", ip, port);
		clientSocket = OpenClientSocket(ip, port);
		if (clientSocket == INVALID_SOCKET)
		{
			printf("Error at connection with %s : %s\n", ip, port);
			printf("EyeX data will not be streamed\n");
		}
		else
		{
			streaming = TRUE;
		}
	}
	Sleep(2000);

	TX_CONTEXTHANDLE hContext = TX_EMPTY_HANDLE;
	TX_TICKET hConnectionStateChangedTicket = TX_INVALID_TICKET;
	TX_TICKET hEventHandlerTicket = TX_INVALID_TICKET;
	BOOL success;

	// initialize and enable the context that is our link to the EyeX Engine.
	success = txInitializeEyeX(TX_EYEXCOMPONENTOVERRIDEFLAG_NONE, NULL, NULL, NULL, NULL) == TX_RESULT_OK;
	success &= txCreateContext(&hContext, TX_FALSE) == TX_RESULT_OK;
	success &= InitializeGlobalInteractorSnapshot(hContext);
	success &= txRegisterConnectionStateChangedHandler(hContext, &hConnectionStateChangedTicket, OnEngineConnectionStateChanged, NULL) == TX_RESULT_OK;
	success &= txRegisterEventHandler(hContext, &hEventHandlerTicket, HandleEvent, NULL) == TX_RESULT_OK;
	success &= txEnableConnection(hContext) == TX_RESULT_OK;

	// let the events flow until a key is pressed.
	if (success) {
		printf("Initialization was successful.\n");
	} else {
		printf("Initialization failed.\n");
	}
	printf("Press X to exit...\n");
	_getch();
	printf("Exiting.\n");

	// disable and delete the context.
	txDisableConnection(hContext);
	txReleaseObject(&g_hGlobalInteractorSnapshot);
	txShutdownContext(hContext, TX_CLEANUPTIMEOUT_DEFAULT, TX_FALSE);
	txReleaseContext(&hContext);

	if (streaming)
	{
		SendFloatClientSocket(clientSocket, -1);
		CloseClientSocket(clientSocket);
	}

	Beep(300, 750);
	return 0;
}