socket绑定问题
This commit is contained in:
parent
80b50dd783
commit
5041412a54
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Reference in New Issue