I am developing a system which has a simple Java server in a private network without Internet connection, a Wifi router that lets mobile devices connect to the network and server, an iOS application that connect to the server using TCP. I have found that when a non-cellular device (e.g: iPod touch) is connected to the network via the Wifi router, it has no issue connecting to the server. However, when connecting an iPhone to the Wifi hotspot, the client application on the device takes more than 5 minutes to locate the server.
I believe that if there is no internet connection, the device would use its cellular network for internet access. From one observation, after connected to the hotspot, some online notifications were still pushed to the phone (I'm 100% percent sure there was no internet access in the network), but after a few minutes, there was no longer internet access and the phone was able to connect to the server.
So the question is how can I achieve the instant connectivity to the server for iPhone? Is there anything that tricks the connected client devices into thinking there is internet access?
Is there any load balancer for the server?
Other option is that you can check the network or wifi connection, if wifi is off then show a prompt.
func isConnectedToNetwork() -> Bool {
var zeroAddress = sockaddr_in(sin_len: 0, sin_family: 0, sin_port: 0, sin_addr: in_addr(s_addr: 0), sin_zero: (0, 0, 0, 0, 0, 0, 0, 0))
zeroAddress.sin_len = UInt8(sizeofValue(zeroAddress))
zeroAddress.sin_family = sa_family_t(AF_INET)
let defaultRouteReachability = withUnsafePointer(&zeroAddress) {
SCNetworkReachabilityCreateWithAddress(nil, UnsafePointer($0)).takeRetainedValue()
}
var flags: SCNetworkReachabilityFlags = 0
if SCNetworkReachabilityGetFlags(defaultRouteReachability, &flags) == 0 {
return false
}
let isReachable = (flags & UInt32(kSCNetworkFlagsReachable)) != 0
let needsConnection = (flags & UInt32(kSCNetworkFlagsConnectionRequired)) != 0
return (isReachable && !needsConnection) ? true : false
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With