socket绑定问题

This commit is contained in:
祝发冬 2022-06-25 19:17:04 +08:00
parent 80b50dd783
commit 5041412a54
1 changed files with 23 additions and 9 deletions

View File

@ -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) {