socket = CFSocketCreate(kCFAllocatorDefault , PF_INET , SOCK_STREAM ,IPPROTO_TCP , kCFSocketNoCallBack, nil, NULL);
if ( NULL == socket )
{
NSLog(@"无法生成连接");
return ;
}
//int n =1 ;
struct sockaddr_in addr4;
memset( &addr4 , 0, sizeof(addr4) );
addr4.sin_len = sizeof(addr4);
addr4.sin_family = AF_INET ;
addr4.sin_port = htons(1200);
addr4.sin_addr.s_addr = inet_addr([@"192.168.1.188" UTF8String ] );
CFDataRef address= CFDataCreate(kCFAllocatorDefault, (UInt8 *)&addr4, sizeof(addr4));
if ( NULL == address )
{
CFSocketInvalidate(socket);
CFRelease(socket);
NSLog(@"无法生成地址");
return ;
}
//可以进行非阻塞设置,select 设置超时
if (CFSocketConnectToAddress(socket, address, 2) != kCFSocketSuccess)
{
CFSocketInvalidate(socket);
CFRelease(socket);
CFRelease(address);
NSLog(@"无法连接设备");
return ;
}
CFRelease(address);
int length = 0;
char buffer[32];
buffer[0] = 03 ;
buffer[1] = 50; //16
buffer[2] = 00;
strcpy(buffer +3 ,"/mnt/disk/config");
length = strlen("/mnt/disk/config") ;
buffer[ length+3 ] = 8; //
buffer[ length+4 ] = 00 ;
strcpy(buffer+length+5, "test.txt");
send(CFSocketGetNative(socket ), buffer, 29, 0 );
int16_t fileCount = -1;
char str[100] ;
memset(str, 0, sizeof(str) );
fd_set rd;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 200000 ;
FD_ZERO(&rd);
FD_SET(CFSocketGetNative(socket), &rd );
// int flag = fcntl(CFSocketGetNative(socket), F_GETFL , 0) ;
// fcntl( CFSocketGetNative(socket), F_SETFL, flag |O_NONBLOCK); //设置异步方式
int retval = select( CFSocketGetNative(socket)+1, &rd , NULL , NULL , &tv ) ;
每次得到的 retval 值 都是 0 ,求大神 指导、
if ( NULL == socket )
{
NSLog(@"无法生成连接");
return ;
}
//int n =1 ;
struct sockaddr_in addr4;
memset( &addr4 , 0, sizeof(addr4) );
addr4.sin_len = sizeof(addr4);
addr4.sin_family = AF_INET ;
addr4.sin_port = htons(1200);
addr4.sin_addr.s_addr = inet_addr([@"192.168.1.188" UTF8String ] );
CFDataRef address= CFDataCreate(kCFAllocatorDefault, (UInt8 *)&addr4, sizeof(addr4));
if ( NULL == address )
{
CFSocketInvalidate(socket);
CFRelease(socket);
NSLog(@"无法生成地址");
return ;
}
//可以进行非阻塞设置,select 设置超时
if (CFSocketConnectToAddress(socket, address, 2) != kCFSocketSuccess)
{
CFSocketInvalidate(socket);
CFRelease(socket);
CFRelease(address);
NSLog(@"无法连接设备");
return ;
}
CFRelease(address);
int length = 0;
char buffer[32];
buffer[0] = 03 ;
buffer[1] = 50; //16
buffer[2] = 00;
strcpy(buffer +3 ,"/mnt/disk/config");
length = strlen("/mnt/disk/config") ;
buffer[ length+3 ] = 8; //
buffer[ length+4 ] = 00 ;
strcpy(buffer+length+5, "test.txt");
send(CFSocketGetNative(socket ), buffer, 29, 0 );
int16_t fileCount = -1;
char str[100] ;
memset(str, 0, sizeof(str) );
fd_set rd;
struct timeval tv;
tv.tv_sec = 0;
tv.tv_usec = 200000 ;
FD_ZERO(&rd);
FD_SET(CFSocketGetNative(socket), &rd );
// int flag = fcntl(CFSocketGetNative(socket), F_GETFL , 0) ;
// fcntl( CFSocketGetNative(socket), F_SETFL, flag |O_NONBLOCK); //设置异步方式
int retval = select( CFSocketGetNative(socket)+1, &rd , NULL , NULL , &tv ) ;
每次得到的 retval 值 都是 0 ,求大神 指导、
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货