NSInputStream get NSStreamEventEndEncountered without reason

  • I use SocketIO project on my iOS app to connect to my node.js server and everything works great until I choose to connect to facebook. When I connect to Facebook I send some data to my server and he answer with some data like "user already connected, user created in database" etc. And after that, my NSInputStream seems to be at 0 and so my connexion is closed. I don't know what to do, I spent 14 hours on that and still get this issue...

    Can you help me with ?
    Looks like the problem is in SRWebSocket.m line 1462

    There is the code in fault :

                case NSStreamEventEndEncountered: {
                    [self _pumpScanner];
                    SRFastLog(@"NSStreamEventEndEncountered %@", aStream);
                    if (aStream.streamError) {
                        [self _failWithError:aStream.streamError];
                    } else {
                        if (self.readyState != SR_CLOSED) {
                            self.readyState = SR_CLOSED;
                            _selfRetain = nil;
                        }

                        if (!_sentClose && !_failed) {
                            _sentClose = YES;
                            // If we get closed in this state it's probably not clean because we should be sending this when we send messages
                            [self _performDelegateBlock:^{
                                if ([self.delegate respondsToSelector:@selector(webSocket:didCloseWithCode:reason:wasClean:)]) {
                                    [self.delegate webSocket:self didCloseWithCode:0 reason:@"Stream end encountered" wasClean:NO];
                                }
                            }];
                        }
                    }

                    break;
                }

                case NSStreamEventHasBytesAvailable: {
                    SRFastLog(@"NSStreamEventHasBytesAvailable %@", aStream);
                    const int bufferSize = 2048;
                    uint8_t buffer[bufferSize];

                    while (_inputStream.hasBytesAvailable) {

                        int bytes_read = [_inputStream read:buffer maxLength:bufferSize];

                        if (bytes_read > 0) {
                            [_readBuffer appendBytes:buffer length:bytes_read];
                        } else if (bytes_read < 0) {
                            [self _failWithError:_inputStream.streamError];
                        }

                        if (bytes_read != bufferSize) {
                            break;
                        }
                    };
                    [self _pumpScanner];
                    break;
                }

    And the result from my server (initalLogin = yes connexion is good you can continue) :

    onData 5:::{"name":"initalLogin","args":[{"guid":"af78bdf0-f17d-ede2-7dd6-22708d1330f7","usedWithFaceBook":true}]}

    start/reset timeout
    NSStreamEventEndEncountered <__NSCFInputStream: 0xab21660>
    onDisconnect ()

    DECONNEXION = The operation couldn’t be completed. (SocketIOError error -4.)

    Can you help me with ?

    Thanks in advance.

    Vavelin Kévin
    Twitter | Blog | LinkedIn
    Entrepreneur
    Developer OS X / iOS
  • On May 4, 2013, at 1:44 PM, Kévin Vavelin <vavelinkevin...> wrote:

    > I use SocketIO project on my iOS app to connect to my node.js server and everything works great until I choose to connect to Facebook.

    Using what protocol? I'm assuming HTTP. If so, then I would first suggest that you stop using a low-level stream API, and use NSURLConnection (or at least CFReadStreamCreateForHTTPRequest) instead. It will make your job so much easier. There are a couple of situations where you might want to use raw streams, but they're rather obscure.

    > When I connect to Facebook I send some data to my server and he answer with some data like "user already connected, user created in database" etc. And after that, my NSInputStream seems to be at 0 and so my connexion is closed.

    If it's HTTP, that's perfectly valid behavior. HTTP 1.0 uses a separate TCP connection for every request, so after the response is sent the socket is closed. HTTP 1.1 supports multiple connections over the same socket, but the client has to indicate that it supports that. (IIRC it depends on what HTTP version string you use in the first line of the request.)

    —Jens
previous month may 2013 next month
MTWTFSS
    1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31    
Go to today