@@ -211,7 +211,7 @@ class SocketParser {
211
211
}
212
212
}
213
213
214
- if stringMessage. hasPrefix ( " 5 " ) {
214
+ if stringMessage. hasPrefix ( " 5 " ) || stringMessage . hasPrefix ( " 6 " ) {
215
215
// Check for message with binary placeholders
216
216
self . parseBinaryMessage ( stringMessage, socket: socket)
217
217
return
@@ -220,10 +220,16 @@ class SocketParser {
220
220
/**
221
221
Begin check for message
222
222
**/
223
- let messageGroups = stringMessage [ " ( \\ d*) \\ /?( \\ w*)?,?( \\ d*)? \\ [ \" (.*?) \" ,?(.*?)? \\ ]$ " ,
224
- NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( )
225
- if messageGroups == nil {
226
- NSLog ( " Error in groups " )
223
+ var messageGroups : [ String ] ?
224
+
225
+ if let groups = stringMessage [ " ( \\ d*) \\ /?( \\ w*)?,?( \\ d*)? \\ [ \" (.*?) \" ,?(.*?)? \\ ]$ " ,
226
+ NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( ) {
227
+ messageGroups = groups
228
+ } else if let ackGroup = stringMessage [ " ( \\ d*) \\ /?( \\ w*)?,?( \\ d*)? \\ [(.*?)? \\ ]$ " ,
229
+ NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( ) {
230
+ messageGroups = ackGroup
231
+ } else {
232
+ NSLog ( " Error parsing message: %s " , stringMessage)
227
233
return
228
234
}
229
235
@@ -289,6 +295,12 @@ class SocketParser {
289
295
// Handles binary data
290
296
class func parseBinaryData( data: NSData , socket: SocketIOClient ) {
291
297
// NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros))
298
+
299
+ if socket. waitingData. count == 0 {
300
+ NSLog ( " Got data when not remaking packet " )
301
+ return
302
+ }
303
+
292
304
let shouldExecute = socket. waitingData [ 0 ] . addData ( data)
293
305
294
306
if shouldExecute {
@@ -339,10 +351,16 @@ class SocketParser {
339
351
/**
340
352
Begin check for binary placeholders
341
353
**/
342
- let binaryGroup = message [ " ^( \\ d*)- \\ /?( \\ w*)?,?( \\ d*)? \\ [( \" .*? \" )?,?(.*)? \\ ]$ " ,
343
- NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( )
354
+ var binaryGroup : [ String ] ?
344
355
345
- if binaryGroup == nil {
356
+ if let groups = message [ " ^( \\ d*)- \\ /?( \\ w*)?,?( \\ d*)? \\ [( \" .*? \" )?,?(.*)? \\ ]$ " ,
357
+ NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( ) {
358
+ binaryGroup = groups
359
+ } else if let groups = message [ " ^( \\ d*)- \\ /?( \\ w*)?,?( \\ d*)? \\ [(.*?)? \\ ]$ " ,
360
+ NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( ) {
361
+ binaryGroup = groups
362
+ } else {
363
+ NSLog ( " Error in parsing binary message: %s " , message)
346
364
return
347
365
}
348
366
0 commit comments