[ad_1]
In order to operate the “Session Traversal Utilities for NAT” (STUN) protocol in SWIFT I first open a NWConnection
with a remote STUN
server of known remoteIP and remotePort like this:
udpConnection = NWConnection(host: remoteIp!, port: remotePort!, using: .udp)
Then I send and receive some packets. I modify remoteIp and remotePort and then WITHOUT CLOSING THE CONNECTION (in order to keep the same Local Endpoint) I try to modify the Remote Endpoint like this:
udpConnection?.currentPath?.remoteEndpoint = NWEndpoint.hostPort(host: remoteIp!, port: remotePort!)
But I receive following error:
Cannot assign to property: ‘remoteEndpoint’ is a ‘let’ constant.
Even cancelling the current connection:
udpConnection?.cancelCurrentEndpoint()
and restarting it:
udpConnection?.restart()
does not help.
The question is: Why is remoteEndpoint a ‘let’ constant not allowing me to modify it?
Thanks in advance.
[ad_2]