I am using Swifter 1.5.0 http library , https://github.com/httpswift/swifter. I am using this code to initialize
enter code here
import Foundation
import Swifter
class Server {
var server: HttpServer
init() {
server = HttpServer()
}
func start(portnumber:UInt16 ) {
server["hello"] = {
.ok(.htmlBody("You asked for....mjkkkh\($0)"))
}
do {
try server.start(portnumber)
print("_______my ip_______Server has started at port \(try server.port())")
} catch {
print("_______my ip_______Server start error: \(error)")
}
}
}
and into my view controller viewDidload, I started the HTTP by :
let server = Server()
server.start(portnumber: 8080)
It works well by testing on similar , calling this url: http://192.168.1.3:8080/hello , where 192.168.1.3 is the IP of my simulator. However , when I need into really iPhone device, I got new IP as 192.168.1.22, but when calling this url http://192.168.1.22:8080/hello , I get error message “Could not send request”.
NB
- real device IP is correct. I ping this IP while device connected, it is sucesfull. If turned Wifi OFF, ping fails.