socket绑定问题
This commit is contained in:
parent
80b50dd783
commit
5041412a54
|
|
@ -24,6 +24,7 @@
|
||||||
@property (nonatomic, strong) NSTimer *loopTimer;
|
@property (nonatomic, strong) NSTimer *loopTimer;
|
||||||
|
|
||||||
@property (nonatomic, assign) int tag;
|
@property (nonatomic, assign) int tag;
|
||||||
|
@property (nonatomic, assign) BOOL bindok;
|
||||||
@property (nonatomic, copy) void(^closeBlock)(void);
|
@property (nonatomic, copy) void(^closeBlock)(void);
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -46,20 +47,33 @@
|
||||||
- (instancetype)init {
|
- (instancetype)init {
|
||||||
if (self = [super init]) {
|
if (self = [super init]) {
|
||||||
self.clientSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
self.clientSocket = [[AsyncUdpSocket alloc] initWithDelegate:self];
|
||||||
|
self.bindok=NO;
|
||||||
UInt16 bindPort = 9954;
|
[self bind];
|
||||||
|
|
||||||
NSError *error;
|
|
||||||
//本地接收端口
|
|
||||||
[self.clientSocket bindToPort:bindPort error:&error];
|
|
||||||
if (error) {
|
|
||||||
[self postmsg: error.localizedDescription];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
-(void)bind
|
||||||
|
{
|
||||||
|
if (!self.bindok)
|
||||||
|
{
|
||||||
|
UInt16 bindPort = 9954;
|
||||||
|
NSError *error;
|
||||||
|
//本地接收端口
|
||||||
|
[self.clientSocket bindToPort:bindPort error:&error];
|
||||||
|
if (error) {
|
||||||
|
[self postmsg:error.localizedDescription];
|
||||||
|
self.bindok=NO;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
self.bindok=YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
- (void)loopTimerTick {
|
- (void)loopTimerTick {
|
||||||
|
[self bind];
|
||||||
if (self.tag == 0) {
|
if (self.tag == 0) {
|
||||||
[self sendConnectHotspotSoketdata];
|
[self sendConnectHotspotSoketdata];
|
||||||
} else if (self.tag == 1) {
|
} else if (self.tag == 1) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue