socket closed by remote peer gcdasyncsocket

Anand picture Anand · Apr 26, 2016 · Viewed 7.4k times · Source

Creating an chat application using xmppframework. When ever I try to connect to the server it connects & disconnected immediately & throws the following error.

error domain=gcdasyncsocketerrordomain code=7 socket closed by remote peer

It happens the same on Adium (chat app) software. Wondering any thing set wrong while setupping the Openfire on AWS Server.

https://community.igniterealtime.org/thread/50643

Please let me know If I need to follow any steps or such.

Thanks for reading.

Answer

Teson Draw picture Teson Draw · Jul 18, 2018

You must store the new socket when the delegate method socket:didAcceptNewSocket been invoked

@property (nonatomic, strong) NSMutableArray *socketsArray;

- (void)viewDidLoad {
    _socketsArray = [[NSMutableArray alloc] init];
}

- (void)socket:(GCDAsyncSocket *)sock didAcceptNewSocket:(GCDAsyncSocket *)newSocket {
    [_socketsArray addObject:newSocket];
}