I am creating a UDP server using the following code.
Creating the UDP server works fine, but I get an error if I use the same port for two apps.
If I force one app to quit, it works fine, but I would like to free the port with viewWillDisappear if possible.
Is that possible?
var udpListner: GCDAsyncUdpSocket?
override func viewDidLoad()
{
udpListner = GCDAsyncUdpSocket(delegate: self, delegateQueue: DispatchQueue.main)
}
override func viewWillAppear(_ animated: Bool)
{
super.viewWillAppear(animated)
do {
try udpListner?.bind(toPort: 8888)
try udpListner?.beginReceiving()
} catch {
print("The port is already in use")
print(error)
}
}
override func viewWillDisappear(_ animated: Bool)
{
super.viewWillDisappear(animated)
udpListner?.close()
}
I am creating a UDP server using the following code.
Creating the UDP server works fine, but I get an error if I use the same port for two apps. If I force one app to quit, it works fine, but I would like to free the port with viewWillDisappear if possible.
Is that possible?