Ok. I've got this code, and proxy still ends up as nil.
I'm still playing with it so hopefully I'll figure out on my own what I'm doing wrong.
import Foundation
class ConnectionHandler: NSObject, NSXPCListenerDelegate {
override init() {
super.init()
print("ConnectionHandler.init()")
}
func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
print("ConnectionHandler.listener()")
newConnection.resume()
return true
}
}
let handler = ConnectionHandler()
let listener = NSXPCListener.anonymous()
let endpoint = listener.endpoint
listener.delegate = handler
listener.resume()
@objc protocol Hello {
func hello()
}
class HelloClass: NSObject, Hello {
override init() {
super.init()
}
func hello() {
print("In HelloClass.hello()")
}
}
let hello = HelloClass()
let connection = NSXPCConnection(listenerEndpoint: endpoint)
connection.exportedInterface = NSXPCInterface(with: Hello.self)
print("Connection = \(connection)")
connection.resume()
let proxy = connection.remoteObjectProxyWithErrorHandler({ error in
print("Got error \(error)")
}) as? Hello
print("Proxy = \(proxy)")
dispatchMain()
Post
Replies
Boosts
Views
Activity
No, I am trying this for macOS. However, it was the only example I could find. :)
I've submitted FB9454265. And am reusing this comment to say something useful!
I never get a chance to call manager.connection.startVPNTunnel because the managers argument is empty ([]). But! I haven't tried NETransparentProxyManager, so I will try that!
Hm. Now I am getting error 9, which is validationFailed. So that means something is wrong with my signing, or one of the plists. That's an improvement from error 1, anyway. ;)
YES. Of all things I forgot to set a team. Yay me! Now it says not connected, which means I get to try to start it, YOU ARE SO AWESOME.
Or NO, the start seems to succeed, but then I get nothing else. Still investigating, but at least I have made progress! Maybe I should commit this.
As I said, "I was just hopeful someone had already saved me a bit of work." It's mostly gruntwork; any cleverness is in how you handle IPv4 and IPv6, and how you handle adding TCP, UDP, ICMP, etc., on top of those.
Ah! THAT WAS IT! In one of my test programs, I was using NETransparentProxyProvider, but in this one I wasn't. That explains why I got confused between the behaviour I saw, the documentation that I read, and what I expected!
You rock, my person.
Hm, maybe that wasn't. I changed it to subclass NETransparentProxyProvider, and my handleNewFlow method isn't being called at all. And all networking (even a ping I started beforehand) dies. Hm hm hm hm.
I should clarify myself -- I have no problem with that! I often tend to use very, very precise working to make sure that what I'm saying is not confused for something else.
That is beautiful code.
grrrr apple did not email me despite this thread being marked as watched.
I haven't tried it yet, but NWPathMonitor / nw_path_monitor_t look promising.
Although I haven't tried on iOS -- this was for macOS.