I used NWConnection.forceCancel and that solved the issue
Post
Replies
Boosts
Views
Activity
I actually don't run this issue if I make my Client abort the connection first.
To simulate waiting I tried to wait before cancelling the listener to disconnect it, but that didn't work either.
I have the feeling that .receive and .send cause the issue, maybe they didn't finish? I am not sure.
I am also not sure if I use installTap correctly to send PCM
That's an interesting thought. But that didn't work.
What I can say though, is that I can start and stop the server how many times I want, it will work fine.
But if I connect as a client to the server and then stop it, I will run into this POSIX Issue. This doesn't happen if I use UDP, btw. If I use the UDP Protocol, I don't recall running into this issue. Only TCP.
Since there's a character limit on the forum:
https://github.com/karl-police/ios_app_mic_pc_test/blob/main/iOS%20Mic%20Test/Include/TCPServer.swift
https://github.com/karl-police/ios_app_mic_pc_test/blob/e9c633f4d9dcd7a402a07922800ed7ead743fa7c/iOS%20Mic%20Test/ViewController.swift#L396
Is this wrapable thing an issue?
var listener: NWListener? = nil
... rest of code
then self.listener?.start(queue: .main)
I believe so? My issue doesn't happen if I change the port from TCP to UDP.
It seems to happen whenever I call NWConnection.receive, to receive from a target connection.
I also use the stateUpdateHandler as the callback instead to check if .ready to then process the connection. Maybe I should try the other way.
Also is there a specific reason for let listener = self.listenerQ or is it just for better optional type handling?
What I am actually doing, is that I don't even re-call .start but instead I re-use the constructor
the server does trigger .cancel() so I am expecting to be able to re-construct it at any times I think?
func cancelConnection(_ connection: NWConnection) {
if let index = self.connectionsArray.firstIndex(where: { $0 === connection }) {
self.connectionsArray.remove(at: index)
}
connection.cancel()
}
func stopServer() {
for connection in self.connectionsArray {
self.cancelConnection(connection) // This closes the connection
}
self.listener?.cancel()
//self.listener?.stateUpdateHandler = nil
//self.listener?.newConnectionHandler = nil
//self.listener = nil
}
Create a NWListener
Wait for a connection.
Connect the Client
Run some things
However, then trigger .cancel() while the client is still connected
Result is after trying to start again it claims that the POSIX is still being taken. EVEN after I close the app, which is strange. That means that I need to wait time for some reason.
[quote='806386022, darkpaw, /thread/764956?answerId=806386022#806386022, /profile/darkpaw']
If you do not pay the annual Developer Fee, any apps you write can only be deployed to your device(s) and must be re-deployed every week.
[/quote]
That sounds fine.
[quote='806386022, darkpaw, /thread/764956?answerId=806386022#806386022, /profile/darkpaw']
You've said you have had troubles creating a Developer Account but you don't say what the issues were? How do you expect us to help you if you don't provide this basic information?
[/quote]
Well, when I click "Enroll" you are given options e.g. Individual and etc. some require a D-U-N-S Number, but that's a business related thing.
If I click on Individual it just tells me that I can't enroll at the time.
[quote='806386022, darkpaw, /thread/764956?answerId=806386022#806386022, /profile/darkpaw']
I find it weird that you've never used Xcode but you've written an app for iOS. How are you deploying it to your iPhone?
[/quote]
gh-actions an alternative would also be .NET MAUI for cross-platform also with gh-actions