@@ -274,6 +274,13 @@ public class CocoaMQTT: NSObject, CocoaMQTTClient, GCDAsyncSocketDelegate, Cocoa
274
274
socket!. writeData ( NSData ( bytes: data, length: data. count) , withTimeout: - 1 , tag: tag)
275
275
}
276
276
277
+ func sendConnectFrame( ) {
278
+ let frame = CocoaMQTTFrameConnect ( client: self )
279
+ send ( frame)
280
+ reader!. start ( )
281
+ delegate? . mqtt ( self , didConnect: host, port: Int ( port) )
282
+ }
283
+
277
284
//AsyncSocket Delegate
278
285
279
286
public func socket( sock: GCDAsyncSocket ! , didConnectToHost host: String ! , port: UInt16 ) {
@@ -295,12 +302,8 @@ public class CocoaMQTT: NSObject, CocoaMQTTClient, GCDAsyncSocketDelegate, Cocoa
295
302
sock. startTLS ( [ kCFStreamSSLPeerName: self . host] )
296
303
#endif
297
304
} else {
298
- let frame = CocoaMQTTFrameConnect ( client: self )
299
- send ( frame)
300
- reader!. start ( )
305
+ sendConnectFrame ( )
301
306
}
302
-
303
- delegate? . mqtt ( self , didConnect: host, port: Int ( port) )
304
307
}
305
308
306
309
public func socket( sock: GCDAsyncSocket ! , didReceiveTrust trust: SecTrust ! , completionHandler: ( ( Bool ) -> Void ) ! ) {
@@ -314,9 +317,7 @@ public class CocoaMQTT: NSObject, CocoaMQTTClient, GCDAsyncSocketDelegate, Cocoa
314
317
#if DEBUG
315
318
NSLog ( " CocoaMQTT: socketDidSecure " )
316
319
#endif
317
- let frame = CocoaMQTTFrameConnect ( client: self )
318
- send ( frame)
319
- reader!. start ( )
320
+ sendConnectFrame ( )
320
321
}
321
322
322
323
public func socket( sock: GCDAsyncSocket ! , didWriteDataWithTag tag: Int ) {
0 commit comments