Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Socket closed by remote peer" - GCDAsyncSocket Error Code 7 #131

Closed
indragiek opened this issue Jan 7, 2013 · 22 comments
Closed

"Socket closed by remote peer" - GCDAsyncSocket Error Code 7 #131

indragiek opened this issue Jan 7, 2013 · 22 comments

Comments

@indragiek
Copy link

After a period of inactivity, the stream disconnects with the following error:

Error Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo=0x7ff222d0ce90 {NSLocalizedDescription=Socket closed by remote peer}, {
    NSLocalizedDescription = "Socket closed by remote peer";
}

The XMPPReconnect module reconnects to the server, but it goes into an infinite loop of periodically disconnecting (with the above error) and reconnecting, and even after reconnecting it doesn't receive any more data from the server until the stream is explicitly disconnected and connected again. I found some old discussion on this issue but wasn't sure if it was still relevant:

https://groups.google.com/forum/#!msg/xmppframework/6RZY3fN73_w/nv8fEGgJiQUJ

Thanks.

@indragiek
Copy link
Author

Quick update: I think the server might be closing the connection because of the idle period. I'll try using the XEP-0199 extension to ping at regular intervals.

@basants
Copy link

basants commented Jan 7, 2013

Generally when the server is closing the connection, you get this error/
Two reasons when the server closes the connection:

  1. You are not sending regular pings if the client idle.
  2. 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.

On Mon, Jan 7, 2013 at 12:14 PM, Indragie Karunaratne <
notifications@github.com> wrote:

Quick update: I think the server might be closing the connection because
of the idle period. I'll try using the XEP-0199 extension to ping at
regular intervals.


Reply to this email directly or view it on GitHubhttps://github.com//issues/131#issuecomment-11942313.

@indragiek
Copy link
Author

Yep, the ping fixed it. Thank you.

@kneeraj1762
Copy link

@indragiek

Did you experience the problem that after a write to socket I don't get a callback that connection disconnected even though my server disconnected it.

@ObjColumnist
Copy link
Collaborator

That could be down to #119 if you are testing on iOS 6?

@Weken
Copy link

Weken commented May 27, 2014

please tell me how to fit it?

@gleeeli
Copy link

gleeeli commented Jan 5, 2016

How to solve this problem???

@gleeeli
Copy link

gleeeli commented Jan 5, 2016

i fixed it by reduce the heart time(7 minute)

@vicky1787
Copy link

Hello Gleeeli, can you please guide how you fixed this problem, I have tried the ping but still the same issue although the ping pong happening.

This also hence making me loose some message while the reconnect is happening and missed stanza. since the server guy is informing that I am connecting to expired session not the resume way that is to be worked.

@gleeeli
Copy link

gleeeli commented Jan 10, 2016

我是将心跳时间从十分钟减到五分钟解决的(reduce the heart time from ten minutes to five minutes)
----- 原始邮件 -----
发件人:"Vicky Dhas (Rappier Pte Ltd)" notifications@github.com
收件人:robbiehanson/XMPPFramework XMPPFramework@noreply.github.com
抄送人:gleeeli gleeeli@sina.com
主题:Re: [XMPPFramework] "Socket closed by remote peer" - GCDAsyncSocket Error Code 7 (#131)
日期:2016年01月06日 15点23分

Hello Gleeeli, can you please guide how you fixed this problem, I have tried the ping but still the same issue although the ping pong happening.

This also hence making me loose some message while the reconnect is happening and missed stanza. since the server guy is informing that I am connecting to expired session not the resume way that is to be worked.


Reply to this email directly or view it on GitHub.

@yql15627285171
Copy link

Please tell me details to fit it,thanks

@posswordkey
Copy link

I want konw anyone solve this problem?? I have this problem now

@githupchenqiang
Copy link

how to deal it I want to know

@gleeeli
Copy link

gleeeli commented Jun 20, 2016

sorry, i‘m not user xmpp when get this mistake。i get this mistake when i use GCDAsyncsocket。i solve this problem by reduce the heart time in five minute。
----- 原始邮件 -----
发件人:QiangChen notifications@github.com
收件人:robbiehanson/XMPPFramework XMPPFramework@noreply.github.com
抄送人:gleeeli gleeeli@sina.com, Comment comment@noreply.github.com
主题:Re: [robbiehanson/XMPPFramework] "Socket closed by remote peer" - GCDAsyncSocket Error Code 7 (#131)
日期:2016年06月17日 18点53分

how to deal it I want to know


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@gleeeli
Copy link

gleeeli commented Jun 20, 2016

你可以加我QQ 295981743
----- 原始邮件 -----
发件人:QiangChen notifications@github.com
收件人:robbiehanson/XMPPFramework XMPPFramework@noreply.github.com
抄送人:gleeeli gleeeli@sina.com, Comment comment@noreply.github.com
主题:Re: [robbiehanson/XMPPFramework] "Socket closed by remote peer" - GCDAsyncSocket Error Code 7 (#131)
日期:2016年06月17日 18点53分

how to deal it I want to know


You are receiving this because you commented.
Reply to this email directly, view it on GitHub, or mute the thread.

@ranjin
Copy link

ranjin commented Sep 19, 2016

11

@nawar
Copy link

nawar commented Nov 8, 2017

this is how to enable it

let autoPing = XMPPAutoPing()
autoPing.activate(xmppStream)

@pmehul55
Copy link

pmehul55 commented Dec 26, 2017

Hello Everyone,

  • MongooseIM 2.0.0

Getting this error in some random time after connected to server and also notice one thing is that it always come when network connection is "Mobile Data"

Domain=GCDAsyncSocketErrorDomain Code=7 "Socket closed by remote peer" UserInfo={NSLocalizedDescription=Socket closed by remote peer}

and already implemented Ping Manager in my code.

    xmppAutPing = XMPPAutoPing(dispatchQueue: DispatchQueue.main)
    xmppAutPing.activate(xmppStream)
    xmppAutPing.addDelegate(self, delegateQueue: DispatchQueue.main)
    xmppAutPing.pingInterval = 2
    xmppAutPing.pingTimeout = 2

Please help.

@jelordreygulle
Copy link

mqttDidDisconnect: Socket closed by remote peer ? what could be the problem?

@skumarm
Copy link

skumarm commented Oct 30, 2018

I am also getting the same error. How to get rid of this.
I am using 5281 as the port number for SSL.
Please help...

@nawar
Copy link

nawar commented Oct 30, 2018

There might be several problems related to that like changing connection speeds, switching from WiFi to wireless data. So use a combination of XEP-0199 and XEP-0184

@vadlani9
Copy link

In my case we are using 2 types of mqtt connections.

  1. mqtt://ourhostname:1884 [Like http://.....] Non secured connections
  2. mqtts://ourhostname:1885 [Like https://....] Securied connections

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests