diff --git a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m index 318c40e..6851c6f 100644 --- a/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m +++ b/Ifish/controllers/leftcontrollers/IFishHotpotUDPHelper.m @@ -24,6 +24,7 @@ @property (nonatomic, strong) NSTimer *loopTimer; @property (nonatomic, assign) int tag; +@property (nonatomic, assign) BOOL bindok; @property (nonatomic, copy) void(^closeBlock)(void); @@ -46,20 +47,33 @@ - (instancetype)init { if (self = [super init]) { self.clientSocket = [[AsyncUdpSocket alloc] initWithDelegate:self]; - - UInt16 bindPort = 9954; - - NSError *error; - //本地接收端口 - [self.clientSocket bindToPort:bindPort error:&error]; - if (error) { - [self postmsg: error.localizedDescription]; - } + self.bindok=NO; + [self bind]; } 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 { + [self bind]; if (self.tag == 0) { [self sendConnectHotspotSoketdata]; } else if (self.tag == 1) {