Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Masna

macrumors newbie
Original poster
Apr 20, 2007
8
0
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
 

Cromulent

macrumors 604
Oct 2, 2006
6,816
1,101
The Land of Hope and Glory
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

Not without any code to see what you are doing.
 

Masna

macrumors newbie
Original poster
Apr 20, 2007
8
0
Not without any code to see what you are doing.

- (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);
}
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.