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

Error when connected to socket #23

Closed
cesarmtaz opened this issue Mar 28, 2018 · 9 comments
Closed

Error when connected to socket #23

cesarmtaz opened this issue Mar 28, 2018 · 9 comments

Comments

@cesarmtaz
Copy link

cesarmtaz commented Mar 28, 2018

Hi,
im getting this error didCloseWithCode 1000, reason: Optional(""Session closed by the container because of the idle timeout."") or didCloseWithCode 1001, reason: Optional("Stream end encountered")

it gets connected but when I subscribe y get this errors this is my channel "/wsc/info/user/"

@cesarmtaz cesarmtaz reopened this Mar 28, 2018
@cesarmtaz cesarmtaz changed the title didCloseWithCode 1001, reason: Optional("Stream end encountered") Error when connected to socket Mar 28, 2018
@WrathChaos WrathChaos self-assigned this Mar 29, 2018
@WrathChaos WrathChaos added the Bug label Mar 29, 2018
@WrathChaos
Copy link
Owner

I know this issue, I'm going to fix it ASAP :) Also, always welcome to PR.

@WrathChaos
Copy link
Owner

Hello @cesarmtaz,
Have you solved this issue or is it still a problem? I need more specific information to fix it. Is it the same as : #31 ?

@meAbhishekTripathi
Copy link

Screenshot 2020-06-03 at 2 36 33 AM

Hi Guys,

While establishing the connection SocketRocket is connected but suddenly it says disconnected with code 1001 as Stream end encountered.

Can you suggest why this happens?

@WrathChaos
Copy link
Owner

Hey @meAbhishekTripathi,
We need to check the code, and have you tried to connect on another platform?

@ngocbaomobile
Copy link

  • @WrathChaos I meet the same issue : "didCloseWithCode 1001, reason: Optional("Stream end encountered")":
    and below is my code to work with socket

<addr.>
func stompClient(client: StompClientLib!, didReceiveMessageWithJSONBody jsonBody: AnyObject?, akaStringBody stringBody: String?, withHeader header: [String : String]?, withDestination destination: String) {
if let del = self.delegate {
guard let list = ListDeviceBO(JSONString: stringBody ?? "") else {
print("canot parse object from socket")
return
}
del.didReceice(self, listDevice: list)
}
print("Destination : (destination)")
print("JSON Body : (String(describing: jsonBody))")
print("String Body : (stringBody ?? "nil")")
}

func stompClientDidDisconnect(client: StompClientLib!) {
    connecSocket()
    print("dis connect stompClient")
}

func stompClientDidConnect(client: StompClientLib!) {
    print("socket connected")
    subscribe()
}

func serverDidSendReceipt(client: StompClientLib!, withReceiptId receiptId: String) {
    print("serverDidSendReceipt : \(receiptId)")
}

func serverDidSendError(client: StompClientLib!, withErrorMessage description: String, detailedErrorMessage message: String?) {
    print("this is descripotion err: \(description)")
    print("this is message err: \(String(describing: message))")
}

func serverDidSendPing() {
    print("serverDidSendPing")
}


// MARK: - Instance Functions
func connecSocket() {
    let requestUrl = NSMutableURLRequest(url: url as URL)
    socketClient.openSocketWithURLRequest(request: requestUrl, delegate: self, connectionHeaders: ["Authorization": "Bearer " + token])
}

func disConnectSocket() {
    socketClient.disconnect()
    unSubscribe()
}

func subscribe() {
    let ack = "ack_\(des)"
    let subsId = "subscription_\(des)"
    let header = ["destination": des, "ack": ack, "id": subsId,"Authorization": "Bearer " + token]
    socketClient.subscribeWithHeader(destination: des, withHeader: header)
}

func unSubscribe() {
    let encoder = JSONEncoder()
    var header = [String : String]()
    var stringBody = [String : String]()
    header["Authorization"] = "Bearer \(token)"
    stringBody["stomp_command"] = "UNSUBSCRIBE"
    stringBody["message"] = des
    do {
        let jsonData = try encoder.encode(stringBody)
        if let jsonString = String(data: jsonData, encoding: .utf8) {
            socketClient.sendMessage(message: jsonString, toDestination: des, withHeaders: header, withReceipt: "")
        }
    } catch _ as NSError {}
}

func sendataToserverWith(ditionaryData: [String: Any]) {
    var header = [String : String]()
    header["Authorization"] = "Bearer \(token)"
    var diction: [String : Any] = ditionaryData
    diction["cases"] = "UP"
    
    let jsonData = try! JSONSerialization.data(withJSONObject: diction, options: JSONSerialization.WritingOptions())
    if let jsonString = String(data: jsonData, encoding: .utf8) {
        socketClient.sendMessage(message: jsonString, toDestination: des, withHeaders: header, withReceipt: "")
    }
}

@ngocbaomobile
Copy link

image

@amit3215
Copy link

@WrathChaos Did you found the solution for that, I am facing the same issue. It's working fine with android and web but in iOS after connection establishment it got disconnected .
didCloseWithCode 1001, reason: Optional("Stream end encountered")

@WrathChaos
Copy link
Owner

WrathChaos commented Aug 11, 2020

Hello @amit3215 and @anhdaden12,
I'm sorry for the late response but I could not reproduce the same problem on the three different Stomp server.
It seems the problem is on your backend side please take a look at these:

If the problem stands still please open a new issue :)

@ngocbaomobile
Copy link

ngocbaomobile commented Sep 15, 2020

@amit3215 on ios platform i solve this problem by send a ping to socket server per 10s. I just send "\n" and it solved my case, like picture below

image

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

No branches or pull requests

5 participants