Reputation: 1973
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.
Upvotes: 5
Views: 10555
Reputation: 17892
I got the same error when i try to use 1885 port numer.
I have added below code in my existing code:
mqttReference?.dispatchQueue = DispatchQueue.global(qos: .userInitiated)
//mqttReference?.logLevel = .debug
mqttReference?.enableSSL = true
mqttReference?.sslSettings = [
GCDAsyncSocketManuallyEvaluateTrust: NSNumber(booleanLiteral: true),
GCDAsyncSocketUseCFStreamForTLS: NSNumber(booleanLiteral: false),
kCFStreamSSLPeerName as String: "" as NSString,
GCDAsyncSocketSSLProtocolVersionMin: NSNumber(integerLiteral: Int(SSLProtocol.tlsProtocol1.rawValue)),
GCDAsyncSocketSSLProtocolVersionMax: NSNumber(integerLiteral: Int(SSLProtocol.tlsProtocol12.rawValue)),
]
My complete code now:
// let clientID = "CocoaMQTT-" + String(ProcessInfo().processIdentifier)
mqttReference = CocoaMQTT(clientID: "", host: mqttProfile.baseURL, port: UInt16(mqttProfile.port))
mqttReference?.username = mqttProfile.userName
mqttReference?.password = mqttProfile.password
mqttReference?.allowUntrustCACertificate = true
mqttReference?.dispatchQueue = DispatchQueue.global(qos: .userInitiated)
//mqttReference?.logLevel = .debug
mqttReference?.enableSSL = true
mqttReference?.sslSettings = [
GCDAsyncSocketManuallyEvaluateTrust: NSNumber(booleanLiteral: true),
GCDAsyncSocketUseCFStreamForTLS: NSNumber(booleanLiteral: false),
kCFStreamSSLPeerName as String: "" as NSString,
GCDAsyncSocketSSLProtocolVersionMin: NSNumber(integerLiteral: Int(SSLProtocol.tlsProtocol1.rawValue)),
GCDAsyncSocketSSLProtocolVersionMax: NSNumber(integerLiteral: Int(SSLProtocol.tlsProtocol12.rawValue)),
]
mqttReference?.autoReconnect = true
mqttReference?.backgroundOnSocket = mqttProfile.allowBackgroundMQTT
mqttReference?.delegate = self
do {
if((mqttReference?.connect())!){
...........
Now it's working fine.
Upvotes: 1
Reputation: 21
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];
}
Upvotes: 2
Reputation: 7602
Please check this github link,
Socket closed by remote peer" - GCDAsyncSocket Error Code 7
It is due to server might be closing the connection because of the idle period. you need to send continues ping to server.
As said in answer ,
Two reasons when the server closes the connection:
- You are not sending regular pings if the client idle.
- You are logging in from some different client with the same credentials, and in the server settings have the setting: Always kick - If there is a resource conflict, immediately kick the other resource. in Server>server settings>resource policy.
Upvotes: 0