NSStream封装

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

//
//  MxTcpStream.h
//
//
//  Created by xialibing on 14-03-03.
//

#import <Foundation/Foundation.h>


typedef enum NetWorkStatus
{
    NetWorkType_None = -1,
    NetWorkType_3G = 0,
    NetWorkType_wifi = 1
    
}NetWorkStatus;



//继承使用本类

@interface MxTcpStream : NSObject

@property(nonatomic,retain) NSString *srvIp;
@property(nonatomic,assign) NSInteger srvPort;
@property(nonatomic,assign)double delayTime;

//是否有网络
+ (BOOL)bHasNetWork;
//没有网络,3g,wifi
+ (NetWorkStatus)getNetWorkStatus;

//设置连接超时时间,不设置默认5秒
- (void)SetDelayOverTime:(double)connectTime;

//打开网络流
- (BOOL)openStream;
//关闭网络流
- (void)closeStream;
//是否可以向缓存发数据
- (BOOL)hasSpace;

//up data
- (BOOL)upData:(void*)data len:(int)datalen;


#pragma mark - 网络事件(继承子类需要实现的方法,都是在主线程中,需要考虑会卡主界面问题)
//处理连接超时,继承子类加处理函数
- (void)NetEvent_ConnectOverTime;
//网络异常,连接断开
- (void)NetEvent_ConnectException;
//对方关闭连接
- (void)NetEvent_TheOtherSideDisconnect;
//连接成功,可以发送数据
- (void)NetEvent_ReadyForUp;
//接收到数据
- (void)NetEvent_RecvData:(char*)data len:(int)datalen;


@end