SwiftSocket icon indicating copy to clipboard operation
SwiftSocket copied to clipboard

Always getting error message

Open ANKITASRI04 opened this issue 7 years ago • 1 comments

func connectSocket(){ let client = TCPClient(address: "192.168.240.1", port: 40200) switch client.connect(timeout: 200) { case .success: switch client.send(string: "GET / HTTP/1.0\n\n" ) { case .success: guard let data = client.read(1024*10) else { return } if let response = String(bytes: data, encoding: .utf8) { print(response)

            }
            
        case .failure(let error):
            print(error)
        }
    case .failure(let error):
        print(error)
    }

}

I am always getting an error"UnknownError" whenever I am trying to run the code

ANKITASRI04 avatar May 25 '18 04:05 ANKITASRI04

When connecting, the underlying C-code is able to catch the following issues:

  • Unresolvable hostname
  • Host closed connection
  • Timeout

Any issue other than these is not currently detectable by Swift as it is just discarded within C.

Are you able to connect to the server on 192.168.240.1:40200 via a command-line tool like nc to verify the server is indeed reachable?

tophcodes avatar Jun 04 '18 13:06 tophcodes