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 didn't send or get any Ping Pong Events #1475

Open
iishabrawy opened this issue Mar 3, 2024 · 5 comments
Open

Socket didn't send or get any Ping Pong Events #1475

iishabrawy opened this issue Mar 3, 2024 · 5 comments

Comments

@iishabrawy
Copy link

iishabrawy commented Mar 3, 2024

Now we have socket server with python with socket io library and the app connected successfully but after 20 seconds the app disconnected

Using SPM .

Library version :

  • SocketIO => 16.1.0
  • Starscream => 4.0.6

Xcode version 15.2.

and this is the socket class :
`
final class SocketIOManager: ObservableObject {
static let sharedInstance = SocketIOManager()

var manager: SocketManager?
private var socket: SocketIOClient?

private let ACCESS_TOKEN = AuthManager.shared.getAccessToken()
private var socketOptions: [String: String] = ["" : ""]

init() {
    prepareSocket()
}

deinit {
    debugPrint("Socket Deinit")
}

func prepareSocket() {
    socketOptions = [
        "Authorization": "Bearer \(ACCESS_TOKEN ?? "")",
        "access-token": ACCESS_TOKEN ?? "",
        "Origin": ""
    ]
    manager = SocketManager(socketURL: URL(string: AppEnvironment.shared.socketBaseUrl)!,
                            config: [
                                .extraHeaders(socketOptions),
                                .compress,
                                .log(true),
                                .forceWebsockets(true)
                            ])
    socket = manager?.socket(forNamespace: "/room")
    handleEvents()
}

func handleEvents() {
    guard let socket else { return }
    socket.on(clientEvent: .connect) { [weak self] data, ack in
        debugPrint("\(Date()) 🧦🔑 socket io connected Now")
        guard let self = self else { return }
    }
    
    socket.on(clientEvent: .disconnect) { [weak self] data, ack in
        debugPrint("\(Date()) 🧦🔑 socket disconnectd")
    }
    socket.on(clientEvent: .error, callback: { [weak self] (data, ack) in
        debugPrint("socket error 🧦🔑  👹👹👹👹👹:\(data)")
        guard let self = self else { return }
    })
    socket.on("Connect_failed", callback: { [weak self] (data, ack) in
        debugPrint("socket Connect_failed 🧦🔑 👹👹👹👹👹:\(data)")            
        guard let self = self else { return }
    })
    socket.on("Reconnect_failed", callback: { [weak self] (data, ack) in
        debugPrint("socket Reconnect_failed 🧦🔑 👹👹👹👹👹:\(data)")            
        guard let self = self else { return }
    })
    socket.on("connect_error", callback: { [weak self] (data, ack) in
        debugPrint("socket connect_error 🧦🔑 👹👹👹👹👹:\(data)")            
        guard let self = self else { return }
    })
    socket.on(clientEvent: .statusChange) { [weak self] (data, ack) in
        debugPrint("socket statusChange 🧦🔑 👹👹👹👹👹:\(data)")
        guard let self = self else { return }
    }

    socket.onAny { event in
        debugPrint("socket onAny 🧦🔑 👹👹👹👹👹:\(event)")
        print("socket Got event: \(event.event), with items: \(event.items)")
    }
    
    socket.on(clientEvent: .ping, callback: { [weak self] (data, ack) in
        debugPrint("socket ping 🧦🔑 👹👹👹👹👹:\(data)")
    })
    
    socket.on(clientEvent: .pong, callback: { [weak self] (data, ack) in
        debugPrint("socket pong 🧦🔑 👹👹👹👹👹:\(data)")
    })        
}
    
func establishConnection() {
    guard let socket else { return }
    if !socketIsConnected() {
        socket.connect()
    }
}

func closeConnection() {
    guard let socket else { return }
    if socketIsConnected() {
        socket.disconnect()
    }
}

func socketIsConnected() -> Bool {
    guard let socket else { return false }
    return (socket.status == .connected)
}

}`

and this is the log from the app starts to connect till it disconnected without any ping pong event

and the server need web socket and needs Origin with empty string cause if I didn't pass it it will not connect anymore

LOG SocketIOClient{/room}: Adding handler for event: connect LOG SocketIOClient{/room}: Adding handler for event: disconnect LOG SocketIOClient{/room}: Adding handler for event: error LOG SocketIOClient{/room}: Adding handler for event: Connect_failed LOG SocketIOClient{/room}: Adding handler for event: Reconnect_failed LOG SocketIOClient{/room}: Adding handler for event: connect_error LOG SocketIOClient{/room}: Adding handler for event: statusChange LOG SocketIOClient{/room}: Adding handler for event: ping LOG SocketIOClient{/room}: Adding handler for event: pong LOG SocketIOClient{/room}: Adding handler for event: roomMessage LOG SocketIOClient{/room}: Adding handler for event: event LOG SocketIOClient{/room}: Handling event: statusChange with data: [connecting, 2] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connecting, 2])" socket Got event: statusChange, with items: Optional([connecting, 2]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connecting, 2]" LOG SocketIOClient{/room}: Joining namespace /room LOG SocketManager: Tried connecting socket when engine isn't open. Connecting LOG SocketManager: Adding engine LOG SocketEngine: Starting engine. Server: https://xxxx.xxxx.xxx LOG SocketEngine: Handshaking LOG SocketEngine: Got message: 0{"sid":"YbEzEaJfe4PFUnLEAAAE","upgrades":[],"pingTimeout":20000,"pingInterval":25000} LOG SocketIOClient{/room}: Handling event: websocketUpgrade with data: [["Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Strict-Transport-Security": "max-age=15724800; includeSubDomains", "Connection": "upgrade", "Date": "Sun, 03 Mar 2024 13:47:13 GMT", "Sec-WebSocket-Accept": "E7jvFBIMxmZHKwLE/5UefHTcefk=", "Upgrade": "websocket"]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: websocketUpgrade items: Optional([[\"Sec-WebSocket-Extensions\": \"permessage-deflate; server_max_window_bits=15\", \"Strict-Transport-Security\": \"max-age=15724800; includeSubDomains\", \"Connection\": \"upgrade\", \"Date\": \"Sun, 03 Mar 2024 13:47:13 GMT\", \"Sec-WebSocket-Accept\": \"E7jvFBIMxmZHKwLE/5UefHTcefk=\", \"Upgrade\": \"websocket\"]])" socket Got event: websocketUpgrade, with items: Optional([["Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Strict-Transport-Security": "max-age=15724800; includeSubDomains", "Connection": "upgrade", "Date": "Sun, 03 Mar 2024 13:47:13 GMT", "Sec-WebSocket-Accept": "E7jvFBIMxmZHKwLE/5UefHTcefk=", "Upgrade": "websocket"]]) LOG SocketManager: Engine opened Connect LOG SocketEngine: Writing ws: 0/room, has data: false LOG SocketEngineWebSocket: Sending ws: 0/room, as type: 4 LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "d0c3d95f-22ef-4aa9-ab27-d09d40da2674"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketEngine: Got message: 40/room,{"sid":"goeqZIigiCCAuQIBAAAF"} LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "2fd44451-75bb-4385-9774-10c55f6eb52d"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "696f4ebe-c389-4d6d-a3ba-52550cda6c7e"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketParser: Parsing 0/room,{"sid":"goeqZIigiCCAuQIBAAAF"} LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: [{ sid = goeqZIigiCCAuQIBAAAF; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketIOClient{/room}: Socket connected LOG SocketIOClient{/room}: Handling event: statusChange with data: [connected, 3] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connected, 3])" socket Got event: statusChange, with items: Optional([connected, 3]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connected, 3]" LOG SocketIOClient{/room}: Handling event: connect with data: ["/room", ["sid": goeqZIigiCCAuQIBAAAF]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: connect items: Optional([\"/room\", [\"sid\": goeqZIigiCCAuQIBAAAF]])" socket Got event: connect, with items: Optional(["/room", ["sid": goeqZIigiCCAuQIBAAAF]]) "2024-03-03 13:47:13 +0000 🧦🔑 socket io connected Now" LOG SocketManager: Starting reconnect LOG SocketIOClient{/room}: Handling event: statusChange with data: [connecting, 2] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connecting, 2])" socket Got event: statusChange, with items: Optional([connecting, 2]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connecting, 2]" LOG SocketIOClient{/room}: Handling event: reconnect with data: ["Socket Disconnected"] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnect items: Optional([\"Socket Disconnected\"])" socket Got event: reconnect, with items: Optional(["Socket Disconnected"]) LOG SocketManager: Trying to reconnect LOG SocketIOClient{/room}: Handling event: reconnectAttempt with data: [-1] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnectAttempt items: Optional([-1])" socket Got event: reconnectAttempt, with items: Optional([-1]) LOG SocketEngine: Starting engine. Server: https://xxxx.xxxx.xxx LOG SocketManager: Scheduling reconnect in 20.01188566948929s LOG SocketEngine: Handshaking LOG SocketEngine: Got message: 0{"sid":"L121mra8WfhO2OdOAAAG","upgrades":[],"pingTimeout":20000,"pingInterval":25000} LOG SocketIOClient{/room}: Handling event: websocketUpgrade with data: [["Date": "Sun, 03 Mar 2024 13:47:33 GMT", "Sec-WebSocket-Accept": "5nt1MC+7vrVmegFTirbkkgIpNhs=", "Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Upgrade": "websocket", "Connection": "upgrade", "Strict-Transport-Security": "max-age=15724800; includeSubDomains"]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: websocketUpgrade items: Optional([[\"Date\": \"Sun, 03 Mar 2024 13:47:33 GMT\", \"Sec-WebSocket-Accept\": \"5nt1MC+7vrVmegFTirbkkgIpNhs=\", \"Sec-WebSocket-Extensions\": \"permessage-deflate; server_max_window_bits=15\", \"Upgrade\": \"websocket\", \"Connection\": \"upgrade\", \"Strict-Transport-Security\": \"max-age=15724800; includeSubDomains\"]])" socket Got event: websocketUpgrade, with items: Optional([["Date": "Sun, 03 Mar 2024 13:47:33 GMT", "Sec-WebSocket-Accept": "5nt1MC+7vrVmegFTirbkkgIpNhs=", "Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Upgrade": "websocket", "Connection": "upgrade", "Strict-Transport-Security": "max-age=15724800; includeSubDomains"]]) LOG SocketManager: Engine opened Connect LOG SocketEngine: Writing ws: 0/room, has data: false LOG SocketEngineWebSocket: Sending ws: 0/room, as type: 4 LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "d0c3d95f-22ef-4aa9-ab27-d09d40da2674"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "2fd44451-75bb-4385-9774-10c55f6eb52d"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "696f4ebe-c389-4d6d-a3ba-52550cda6c7e"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 40/room,{"sid":"nPq4HcMNZVoA2CFQAAAH"} LOG SocketParser: Parsing 0/room,{"sid":"nPq4HcMNZVoA2CFQAAAH"} LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: [{ sid = nPq4HcMNZVoA2CFQAAAH; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketIOClient{/room}: Socket connected LOG SocketIOClient{/room}: Handling event: statusChange with data: [connected, 3] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connected, 3])" socket Got event: statusChange, with items: Optional([connected, 3]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connected, 3]" LOG SocketIOClient{/room}: Handling event: connect with data: ["/room", ["sid": nPq4HcMNZVoA2CFQAAAH]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: connect items: Optional([\"/room\", [\"sid\": nPq4HcMNZVoA2CFQAAAH]])" socket Got event: connect, with items: Optional(["/room", ["sid": nPq4HcMNZVoA2CFQAAAH]]) "2024-03-03 13:47:33 +0000 🧦🔑 socket io connected Now" LOG SocketManager: Starting reconnect LOG SocketIOClient{/room}: Handling event: statusChange with data: [connecting, 2] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connecting, 2])" socket Got event: statusChange, with items: Optional([connecting, 2]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connecting, 2]" LOG SocketIOClient{/room}: Handling event: reconnect with data: ["Socket Disconnected"] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnect items: Optional([\"Socket Disconnected\"])" socket Got event: reconnect, with items: Optional(["Socket Disconnected"]) LOG SocketManager: Trying to reconnect LOG SocketIOClient{/room}: Handling event: reconnectAttempt with data: [-1] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnectAttempt items: Optional([-1])" socket Got event: reconnectAttempt, with items: Optional([-1]) LOG SocketManager: Scheduling reconnect in 18.618264492550644s LOG SocketEngine: Starting engine. Server: https://xxxx.xxxx.xxx LOG SocketManager: Trying to reconnect LOG SocketEngine: Handshaking LOG SocketIOClient{/room}: Handling event: reconnectAttempt with data: [-2] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnectAttempt items: Optional([-2])" socket Got event: reconnectAttempt, with items: Optional([-2]) LOG SocketManager: Tried connecting an already active socket LOG SocketManager: Scheduling reconnect in 29.773148280500056s LOG SocketEngine: Got message: 0{"sid":"usYInQDN5AzCL3n0AAAI","upgrades":[],"pingTimeout":20000,"pingInterval":25000} LOG SocketIOClient{/room}: Handling event: websocketUpgrade with data: [["Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Upgrade": "websocket", "Date": "Sun, 03 Mar 2024 13:47:54 GMT", "Strict-Transport-Security": "max-age=15724800; includeSubDomains", "Connection": "upgrade", "Sec-WebSocket-Accept": "feDBmOAZdirYPyko9VzL9UbhBTg="]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: websocketUpgrade items: Optional([[\"Sec-WebSocket-Extensions\": \"permessage-deflate; server_max_window_bits=15\", \"Upgrade\": \"websocket\", \"Date\": \"Sun, 03 Mar 2024 13:47:54 GMT\", \"Strict-Transport-Security\": \"max-age=15724800; includeSubDomains\", \"Connection\": \"upgrade\", \"Sec-WebSocket-Accept\": \"feDBmOAZdirYPyko9VzL9UbhBTg=\"]])" socket Got event: websocketUpgrade, with items: Optional([["Sec-WebSocket-Extensions": "permessage-deflate; server_max_window_bits=15", "Upgrade": "websocket", "Date": "Sun, 03 Mar 2024 13:47:54 GMT", "Strict-Transport-Security": "max-age=15724800; includeSubDomains", "Connection": "upgrade", "Sec-WebSocket-Accept": "feDBmOAZdirYPyko9VzL9UbhBTg="]]) LOG SocketManager: Engine opened Connect LOG SocketEngine: Writing ws: 0/room, has data: false LOG SocketEngineWebSocket: Sending ws: 0/room, as type: 4 LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "a95d2cef-1c35-4711-9c47-0bccb8f6e6c3"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"d0c3d95f-22ef-4aa9-ab27-d09d40da2674"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "d0c3d95f-22ef-4aa9-ab27-d09d40da2674"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"2fd44451-75bb-4385-9774-10c55f6eb52d"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "2fd44451-75bb-4385-9774-10c55f6eb52d"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 42/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Parsing 2/room,["event",{"eventType":"userJoined","userId":"a49f33c4-1988-425a-8155-6d96892c5880","roomId":"696f4ebe-c389-4d6d-a3ba-52550cda6c7e"}] LOG SocketParser: Decoded packet as: SocketPacket {type: 2; data: [event, { eventType = userJoined; roomId = "696f4ebe-c389-4d6d-a3ba-52550cda6c7e"; userId = "a49f33c4-1988-425a-8155-6d96892c5880"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketEngine: Got message: 40/room,{"sid":"_C4IoHk7sCaOUngfAAAJ"} LOG SocketParser: Parsing 0/room,{"sid":"_C4IoHk7sCaOUngfAAAJ"} LOG SocketParser: Decoded packet as: SocketPacket {type: 0; data: [{ sid = "_C4IoHk7sCaOUngfAAAJ"; }]; id: -1; placeholders: -1; nsp: /room} LOG SocketIOClient{/room}: Socket connected LOG SocketIOClient{/room}: Handling event: statusChange with data: [connected, 3] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connected, 3])" socket Got event: statusChange, with items: Optional([connected, 3]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connected, 3]" LOG SocketIOClient{/room}: Handling event: connect with data: ["/room", ["sid": _C4IoHk7sCaOUngfAAAJ]] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: connect items: Optional([\"/room\", [\"sid\": _C4IoHk7sCaOUngfAAAJ]])" socket Got event: connect, with items: Optional(["/room", ["sid": _C4IoHk7sCaOUngfAAAJ]]) "2024-03-03 13:47:54 +0000 🧦🔑 socket io connected Now" LOG SocketManager: Starting reconnect LOG SocketIOClient{/room}: Handling event: statusChange with data: [connecting, 2] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: statusChange items: Optional([connecting, 2])" socket Got event: statusChange, with items: Optional([connecting, 2]) "socket statusChange 🧦🔑 👹👹👹👹👹:[connecting, 2]" LOG SocketIOClient{/room}: Handling event: reconnect with data: ["Socket Disconnected"] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnect items: Optional([\"Socket Disconnected\"])" socket Got event: reconnect, with items: Optional(["Socket Disconnected"]) LOG SocketManager: Trying to reconnect LOG SocketIOClient{/room}: Handling event: reconnectAttempt with data: [-1] "socket onAny 🧦🔑 👹👹👹👹👹:SocketAnyEvent: Event: reconnectAttempt items: Optional([-1])" socket Got event: reconnectAttempt, with items: Optional([-1]) LOG SocketManager: Scheduling reconnect in 16.974102096344986s

Could you tell me what is the issue ??
cause it working in android & postman without any issue and the connection is stable.

@iishabrawy
Copy link
Author

@nuclearace
could you look into this issue please ..

@mkukawski
Copy link

I have the same problem

@iishabrawy
Copy link
Author

iishabrawy commented Mar 17, 2024

@mkukawski
I fixed it in my situation by pass Sec-WebSocket-Origin as extra headers with empty string
"Sec-WebSocket-Origin": ""

and this is my extra headers:

socketOptions = [ "Origin": "", "Sec-WebSocket-Origin": "" ]

and removed compress from the manger instance :

    manager = SocketManager(socketURL: URL(string: AppEnvironment.shared.socketBaseUrl)!,
                            config: [
                                .extraHeaders(socketOptions),
                                .secure(true),
                                .forceWebsockets(true),
                                .reconnects(true),
                                .reconnectWait(1)
                            ])

I hope this will fix the issue for you .

@mkukawski
Copy link

I tried that:

let socketOptions = [ "Origin": "", "Sec-WebSocket-Origin": "" ]
        self.socketManager = SocketManager(socketURL: url, config: [
            .extraHeaders(socketOptions),
                .log(true), .forceWebsockets(true), .reconnects(true), .reconnectWait(1), .reconnectWaitMax(10), .reconnectAttempts(1000)])

        // Create a Socket.IO client
        self.socket = socketManager!.socket(forNamespace: "/broadcastMetadata/\(broadcastIdentifier)")
        self.socket!.on(clientEvent: .error) { data, ack in
            print("Socket error")
            print(data)
        }
        self.socket!.on(clientEvent: .ping) { data, ack in
            print("Ping")
            print(data)
        }
        self.socket!.on(clientEvent: .pong) { data, ack in
            print("Pong")
            print(data)
        }
        self.socket!.on(clientEvent: .statusChange) { data, ack in
            print("Socket statusChange \(data)")
            print(data)
        }

        self.socket!.on(clientEvent: .connect) { data, ack in
            print("Socket connected")
        }

And still disconnects every 20s or so, log around disconnection just says :

LOG SocketIOClient{/broadcastMetadata/dbcf27f7-783f-46a4-8812-54ec1bb5bdb1}: Handling event: ... (previous event)
LOG SocketManager: Starting reconnect
LOG SocketIOClient{/broadcastMetadata/dbcf27f7-783f-46a4-8812-54ec1bb5bdb1}: Handling event: statusChange with data: [connecting, 2]
Socket statusChange [connecting, 2]
[connecting, 2]

@umeshsRide
Copy link

Use the following code to initialize the socket. This will ensure that the socket starts receiving ping-pong events, and it will prevent the socket from disconnecting:
manager = SocketManager(socketURL: url,
config: [.connectParams(socketConfig ?? [:]),
.log(isLogEnabled),
.compress,
.forceWebsockets(true),
.forcePolling(true),
.reconnects(true),
.forceNew(true)])

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

3 participants