AsyncSocket
来源:互联网 发布:mac截图 编辑:程序博客网 时间:2024/06/05 11:45
//下载地址 https://github.com/robbiehanson/CocoaAsyncSocket
#import "ViewController.h"
#import "GCDAsyncSocket.h"
#import "GCDAsyncUdpSocket.h"
#import "AsyncSocket.h"
@interface ViewController ()<GCDAsyncSocketDelegate>
{
NSInputStream *inputStream;
NSOutputStream *outputStream;
}
@property(nonatomic,strong)AsyncSocket *asyncSocket;
@end
@implementation ViewController
- (void)viewDidLoad {
[superviewDidLoad];
self.asyncSocket=[[AsyncSocketalloc]initWithDelegate:self];
[selftestSocket];
}
-(void)testSocket{
NSData* xmlData = [@"testdata"dataUsingEncoding:NSUTF8StringEncoding];
if ([self.asyncSocketconnectToHost:@"此处为服务器地址"onPort:80error:nil]) {
NSLog(@"success");
}else{
NSLog(@"failed");
}
[self.asyncSocketwriteData:xmlData withTimeout:-1tag:1];
}
- (void)onSocket:(AsyncSocket *)sock didConnectToHost:(NSString *)host port:(UInt16)port{
[self.asyncSocketreadDataWithTimeout:-1tag:0];
NSLog(@"%@",host);
}
- (void)onSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err
{
NSLog(@"Error");
}
- (void)onSocketDidDisconnect:(AsyncSocket *)sock
{
NSLog(@"connect is failure");
self.asyncSocket =nil;
}
- (void)onSocketDidSecure:(AsyncSocket *)sock{
}
- (void)onSocket:(AsyncSocket *)sock didReadData:(NSData *)data withTag:(long)tag{
NSString* aStr = [[NSStringalloc] initWithData:dataencoding:NSUTF8StringEncoding];
NSLog(@"Hava received datas is :%@",aStr);
[self.asyncSocketreadDataWithTimeout:-1tag:0];
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- AsyncSocket
- ASyncSocket库
- AsyncSocket详解
- IOS AsyncSocket
- AsyncSocket详解 .
- AsyncSocket详解
- AsyncSocket详解
- AsyncSocket编程
- IOS---AsyncSocket
- iOS AsyncSocket
- 笔记:c++的const类成员函数(1)
- RabbitMQ消息队列(一): Detailed Introduction 详细介绍
- 比较Java不同压缩算法的性能
- css3常用属性animation-play-state的使用技巧
- 深入理解sizeof
- AsyncSocket
- OpenCV立体相机标定Stereo Calibration与校准检验Rectification详述
- Linux修改系统时间
- 21条最佳实践Mysql数据库调优和性能优化的
- QBXT DAY1
- 1038. Recover the Smallest Number (30)
- 心得 - 面向对象和面向过程的区别
- picasso使用
- SQL Server数据类型转换方法