@@ -211,7 +211,7 @@ class SocketParser {
211211 }
212212 }
213213
214- if stringMessage. hasPrefix ( " 5 " ) {
214+ if stringMessage. hasPrefix ( " 5 " ) || stringMessage . hasPrefix ( " 6 " ) {
215215 // Check for message with binary placeholders
216216 self . parseBinaryMessage ( stringMessage, socket: socket)
217217 return
@@ -220,10 +220,16 @@ class SocketParser {
220220 /**
221221 Begin check for message
222222 **/
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)
227233 return
228234 }
229235
@@ -289,6 +295,12 @@ class SocketParser {
289295 // Handles binary data
290296 class func parseBinaryData( data: NSData , socket: SocketIOClient ) {
291297 // NSLog(data.base64EncodedStringWithOptions(NSDataBase64EncodingOptions.allZeros))
298+
299+ if socket. waitingData. count == 0 {
300+ NSLog ( " Got data when not remaking packet " )
301+ return
302+ }
303+
292304 let shouldExecute = socket. waitingData [ 0 ] . addData ( data)
293305
294306 if shouldExecute {
@@ -339,10 +351,16 @@ class SocketParser {
339351 /**
340352 Begin check for binary placeholders
341353 **/
342- let binaryGroup = message [ " ^( \\ d*)- \\ /?( \\ w*)?,?( \\ d*)? \\ [( \" .*? \" )?,?(.*)? \\ ]$ " ,
343- NSRegularExpressionOptions . DotMatchesLineSeparators] . groups ( )
354+ var binaryGroup : [ String ] ?
344355
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)
346364 return
347365 }
348366
0 commit comments