I tried to connect to a esp32 room 32 using sockets. but when trying to connect to the micro-prozessor which works as the server the client (coded in swift) says:
2021-03-20 15:34:55.157403+0100 connectionPlayground[2083:81450] [connection] nw_read_request_report [C1] Receive failed with error "Socket is not connected"
2021-03-20 15:34:55.157543+0100 connectionPlayground[2083:81450] [connection] nw_socket_get_input_frames [C1:2] recvmsg(fd 11, 1024 bytes) [54: Connection reset by peer]
2021-03-20 15:34:55.158086+0100 connectionPlayground[2083:81450] Connection 1: received failure notification
2021-03-20 15:34:55.158410+0100 connectionPlayground[2083:81450] [connection] nw_connection_copy_connected_local_endpoint [C1] Connection has no connected path
2021-03-20 15:34:55.158456+0100 connectionPlayground[2083:81450] [connection] nw_connection_copy_connected_remote_endpoint [C1] Connection has no connected path
failure:Error Domain=NSPOSIXErrorDomain Code=57 "Socket is not connected" UserInfo={NSErrorFailingURLStringKey=http://172.20.10.2/, NSErrorFailingURLKey=http://172.20.10.2/}
I also changed the info.plist file and added this:
?xml version="1.0" encoding="UTF-8"?
!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"
plist version="1.0"
dict
keyNSAllowsLocalNetworking/key
true/
keyNSAllowsArbitraryLoads/key
true/
keyNSExceptionDomains/key
dict
key172.20.10.2/key
dict
keyNSTemporaryExceptionMinimumTLSVersion/key
stringTLSv1.1/string
keyNSIncludesSubdomains/key
true/
keyNSTemporaryExceptionAllowsInsecureHTTPLoads/key
true/
/dict
/dict
/dict
/plist
my current program looks like this:
@IBAction func start(_ sender: Any) {
print("start");
let session = URLSession(configuration: .default, delegate: self, delegateQueue: OperationQueue())
let url = URL(string: "ws://172.20.10.2/")!
let webSocketTask = session.webSocketTask(with: url)
webSocketTask.receive { (result) in
print("result")
switch result{
case .success(let message):
switch message {
case .string(let text):
print(text)
default:
break
}
case .failure(let error):
print("failure:\(error)")
break
default:
break
}
}
webSocketTask.resume()
}
Selecting any option will automatically load the page