101 lines
2.4 KiB
Objective-C
101 lines
2.4 KiB
Objective-C
//
|
|
// Socketsingleton.h
|
|
// Ifish
|
|
//
|
|
// Created by imac on 15/10/17.
|
|
// Copyright © 2015年 imac. All rights reserved.
|
|
//
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import "AsyncSocket.h"
|
|
|
|
#import "manulswitchMSModel.h"
|
|
#import "XuToLightModel.h"
|
|
#import "JiaReWenDuModel.h"
|
|
//#define DEFINE_SHARED_INSTANCE_USING_BLOCK(block) \
|
|
//static dispatch_once_t onceToken = 0; \
|
|
//__strong static id sharedInstance = nil; \
|
|
//dispatch_once(&onceToken, ^{ \
|
|
//sharedInstance = block(); \
|
|
//}); \
|
|
//return sharedInstance; \
|
|
|
|
//enum{
|
|
// SocketOfflineByServer,// 服务器掉线,默认为0
|
|
// SocketOfflineByUser, // 用户主动cut
|
|
//};
|
|
//typedef NS_ENUM(NSInteger,soketofflineStyle){
|
|
// SocketOfflineByServer,// 服务器掉线,默认为0
|
|
// SocketOfflineByUser // 用户主动cut
|
|
//};
|
|
//监听soket
|
|
|
|
@protocol IfishCommuniteDelegate <NSObject>
|
|
|
|
//设备登陆成功后返回数据
|
|
-(void)socketDidGetBackmsgData:(NSData *)data onsoket:(AsyncSocket *)sock;
|
|
|
|
//已断开连接
|
|
|
|
- (void)ifishSocketDidDisconnect:(AsyncSocket *)sock;
|
|
|
|
//已经连接成功
|
|
|
|
-(void)ifishSocket:(AsyncSocket *)sock ifishSocketdidConnectToHost:(NSString *)host port:(UInt16)port;
|
|
|
|
//发送数据完成
|
|
|
|
- (void)ifishSocket:(AsyncSocket *)sock didWriteDataWithTag:(long)tag;
|
|
|
|
//错误断开
|
|
|
|
-(void)ifishSocket:(AsyncSocket *)sock willDisconnectWithError:(NSError *)err;
|
|
|
|
// 将要连接
|
|
|
|
- (BOOL)ifishSocketWillConnect:(AsyncSocket *)sock;
|
|
|
|
//新的soket
|
|
|
|
- (void)ifishSocket:(AsyncSocket *)sock didAcceptNewSocket:(AsyncSocket *)newSocket;
|
|
|
|
//设备登陆成功
|
|
|
|
-(void)ifishDeviceLogInSuccees;
|
|
|
|
//设备登陆失败
|
|
|
|
-(void)ifishDeviceLogInFail;
|
|
|
|
@end
|
|
|
|
@interface Socketsingleton : NSObject
|
|
|
|
@property (nonatomic, strong) AsyncSocket *clientSocket; // socket
|
|
@property (nonatomic, copy ) NSString *socketHost; // socket的Host
|
|
@property (nonatomic, assign) UInt16 socketPort; // socket的prot
|
|
@property (nonatomic, retain) NSTimer *connectTimer; // 计时器 //心跳
|
|
@property (nonatomic, weak) id<IfishCommuniteDelegate> communiteDelegate;
|
|
|
|
+ (Socketsingleton *)sharedInstance;
|
|
|
|
-(void)cutOffSocket; // 断开socket连接
|
|
|
|
-(void)socketConnectHost;
|
|
|
|
@property(nonatomic,copy) NSString *macAddress;
|
|
|
|
|
|
//将通信指令写入soket
|
|
|
|
|
|
-(void)soketWriteData:(NSData *)data;
|
|
|
|
|
|
-(void)setSoketLightDataWith:(manulswitchMSModel *)model;
|
|
|
|
-(void)setXuToSoketLightDataWith:( XuToLightModel *)model;
|
|
-(void)setXuToJiaReBangDataWith:( JiaReWenDuModel *)model;
|
|
@end
|
|
|