Problem with BSD Sockets in App

Discussion in 'Mac Programming' started by Masna, Jul 12, 2008.

  1. Masna macrumors newbie

    Joined:
    Apr 20, 2007
    #1
    I'm trying to use BSD sockets to connect to a server script on a remote computer. I have a bunch of socket functions run at the click of a button. However, the app freezes as soon as the connect() function is hit. Any idea why that's happening/how to avoid it?

    Thanks
     
  2. Cromulent macrumors 603

    Cromulent

    Joined:
    Oct 2, 2006
    Location:
    The Land of Hope and Glory
    #2
    Not without any code to see what you are doing.
     
  3. Masna thread starter macrumors newbie

    Joined:
    Apr 20, 2007
    #3
    - (void)changeLights:(id)sender
    {
    int n;
    char buffer[201];
    struct sockaddr_in serverAddress;
    char *achar = ">N,ON\n";


    NSLog(@"%d", sockfd);
    //NSFileHandle *fileHandle = [[NSFileHandle alloc] initWithFileDescriptor:sockfd];

    bzero( &serverAddress, sizeof(serverAddress) );
    serverAddress.sin_family = AF_INET;
    serverAddress.sin_port = htons( 4999 );

    inet_pton( AF_INET, "69.116.166.132", &serverAddress.sin_addr );

    if(connect( sockfd, (struct sockaddr *)&serverAddress, sizeof(serverAddress)) < 0){
    return;
    }

    if(lightSwitch.on){
    achar = ">N,ON\n";
    } else {
    achar = ">N,OFF\n";
    }

    NSString *streamingString;
    NSMutableString *finishedString = [[NSMutableString string] retain];
    /*while ( n = read( sockfd, buffer, 200) ) {
    buffer[n] = 0;
    streamingString = [[NSString alloc] initWithCString:buffer];
    [finishedString appendString:streamingString];
    [streamingString release];
    //printf( buffer );
    }*/

    testView.text = [[finishedString copy] retain];
    [finishedString release];

    //write( sockfd, achar, strlen(achar));
    //close(sockfd);
    }
     

Share This Page