1 / 13
文档名称:

网络编程CFSocketRef.doc

格式:doc   大小:64KB   页数:13页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

网络编程CFSocketRef.doc

上传人:yzhluyin9 2019/9/1 文件大小:64 KB

下载得到文件列表

网络编程CFSocketRef.doc

相关文档

文档介绍

文档介绍:(CFAllocatorRefallocator,SInt32protocolFamily,SInt32socketType,SInt32protocol,CFOptionFlagscallBackTypes,CFSocketCallBackcallout,constCFSocketContext*context);-(void)setTextInMainThread:(NSString*)text{NSRangeendRange;=[];=[textlength];=[:[@"server:"stringByAppendingString:text]];;[:endRange];}-(void)readStream{charbuffer[255];NSAutoreleasePool*pool=[[NSAutoreleasePoolalloc]init];while(recv(CFSocketGetNative(_socket),buffer,sizeof(buffer),0)){NSString*s=[NSStringstringWithUTF8String:buffer];[selfperformSelectorOnMainThread:***@selector(setTextInMainThread:)withObject:swaitUntilDone:YES];}[poolrelease];}staticvoidTCPServerConnectCallBack(CFSocketRefsocket,CFSocketCallBackTypetype,CFDataRefaddress,constvoid*data,void*info){if(data!=NULL){UIAlertView*alert=[[UIAlertViewalloc]initWithTitle:@""message:@"连接失败"delegate:nilcancelButtonTitle:@"关闭"otherButtonTitles:nil];[alertshow];[alertrelease];return;}TCPClientDemoAppDelegate*delegate=(TCPClientDemoAppDelegate*)info;[delegateperformSelectorInBackground:***@selector(readStream)withObject:nil];[:YES];[[NSNotificationCenterdefaultCenter]addObserver::***@selector(keyboardWillShown:)name:UIKeyboardWillShowNotificationobject:nil];[[NSNotificationCenterdefaultCenter]addObserver::***@selector(keyboardWillHidden:)name:UIKeyboardWillHideNotificationobject:nil];}-(void)doConnect{//CFSocketContext存放一些CFSocketRef的相关信息CFSocketContextCTX={0,self,NULL,NULL,NULL};//CFSocketCreate函数是用来创建一个CFSocketRef,第一个参数是表示由系统默认的allocator来为CFSocketRef分配一个内存空间。//第二个参数表示profocolFamily(协议簇)//第三个参数表示socketType(socket的类型流、数据段、顺序包...)//第四个参数表示protocol(协议t