2

I'm running Spring Boot v2.2 with a correct WebSocketHandler(). I'm confident the server is correct because when I go to http://websocket.org/echo.html and attempt to connect to our server, we can verify connection on both the server and the browser client.

However, in iOS (I'm testing on 2 simulators - iOS 12 and iOS 13.3), I'm not able to connect. I'm now attempting to utilize Starscream. (attempting this with Socket.io led to unsolvable issues and attempting this with SocketRocket led to issues simply getting it to build on iOS 13.3.)

The issue I'm facing now is that Starscream just fails silently when attempting to connect to the address of our java server (ws://127.0.0.1:8080/socket). When I say fail silently, I mean that nothing happens on the client or server indicating that there was an error but also by debugging I can see that isConnected = false on our iOS socket.

To attempt to fix this issue I've tried:

  • adding App Transport Security Settings -> Allow Arbitrary Loads = YES in Info.plist.
  • adding NSExceptionDomains -> NSExceptionAllowsInsecureHTTPLoads = YES in Info.plist.
  • utilizing both localhost and 127.0.0.1, both with /socket or / and HTTP instead of ws/wss.
  • I was even able to effectively query google.com with a GET request using native Swift.
import Foundation
import Starscream

class WinkNetworkClient : WebSocketDelegate {
    private var isConnected : Bool = false

    init() {
        let socket: WebSocket =
            WebSocket(request:
                URLRequest(url: URL(string: "ws://127.0.0.1:8080/socket")!), certPinner: FoundationSecurity(allowSelfSigned: true))
        socket.delegate = self
        socket.connect()
        // socket.write(string: "Hi Server!")
        print("Client done")
    }

    func didReceive(event: WebSocketEvent, client: WebSocket) {
        switch event {
        case .connected(let headers):
            isConnected = true
            print("websocket is connected: \(headers)")
        case .disconnected(let reason, let code):
            isConnected = false
            print("websocket is disconnected: \(reason) with code: \(code)")
        case .text(let string):
            print("Received text: \(string)")
        case .binary(let data):
            print("Received data: \(data.count)")
        case .ping(_):
            break
        case .pong(_):
            break
        case .viabilityChanged(_):
            break
        case .reconnectSuggested(_):
            break
        case .cancelled:
            isConnected = false
        case .error(let error):
            isConnected = false
            print("error connecting to websocket: \(String(describing: error))")
        }
    }
}

I'm very lost as to what the issue might be. What am I doing wrong?

the Tin Man
  • 158,662
  • 42
  • 215
  • 303
doyeka
  • 31
  • 1
  • 5
  • 1
    *I'm confident the server is correct because \[edit\] **compelling reason***. This question is not about Java, spring boot or websocket. I know Java. I know websockets. I know spring-boot. I don't know starscream (or really know swift/obj-c). And I can't help you. At all. Thus those tags don't help you. I wouldn't necessarily add obj-c but this definitely looks like [tag:swift] would be more appropriate than java, spring-boot or websocket. – Elliott Frisch Apr 16 '20 at 01:47
  • For me it also didn't work on simulators, but finally get it working on device. – landonandrey Apr 22 '21 at 08:06

0 Answers0