Question

I'm working on some networking code for an iPhone application that interfaces with a Python Twisted backend. I've been running into a problem recently where it appears as though either my NSOutputStream is doubling up the payload on send OR twisted is doubling up the payload on receive.

I'm using the "Apple Recommended" style of TCP sockets, E.G. non-polling.

The process is as follows:
CLIENT
    - NSStreamEventHasSpaceAvailable: send a packet of X bytes of data
    - NSStreamEventHasSpaceAvailable: send another packet of Y bytes of data
SERVER
    - Twisted receives packet of size (X + Y) bytes

I'm making sure I explicitly don't send data if the status of the outputStream is "NSStreamStatusWriting". Also ensuring that data is not allowed to be sent from the client if NSStreamEventHasSpaceAvailable has not been thrown.

Any ideas as to what may be causing this double-up/merger of the payload? The Twisted code is fairly straight-forward, using the standard dataReceived in my Protocol:

    def dataRecieved(self, data):
        # do logic in order to decide how to handle data
        # ...
        # print of len(data) here reveals merged packet size

iOS code is fairly standard as well:

    if (eventCode == NSStreamEventHasSpaceAvailable)
    {
        [outputStream write:[packet getData] maxLength:[packet getPacketSize]];
    }
    // [packet getData] simply returns a standard UInt8 array. 
    // [packet getPacketSize] returns the size of that array.

When the above iOS code is called twice in a row (e.g., sending two packets one after another), the twisted code reports the merged data size.

Thanks in advance for any advice or suggestions.

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top