Hi there,
I've half succeeded in creating a SwiftUI app which allows me to connect to another piece of software via nwConnection with a host (ip address) and port.
I modified the code from this site https://rderik.com/blog/building-a-server-client-aplication-using-apple-s-network-framework/ (obviously only the client part as my server is already setup and functioning).
The server I connect to simply broadcasts variable names and values as strings which I can successfully parse and display in a list.
The problem I have is when I try to disconnect (or cancel) the connection and reconnect. I get the following errors:
nw_connection_set_state_changed_handler [C1] Cannot set state changed handler after cancel
I've tried reading the Apple documentation as well as following along line by line with the above example and although this message makes sense in a general way, I have no idea how to resolve the issue. I don't want to have to have the users close/reopen the app every time they want to close and reopen the connection.
I'm finding it difficult to find tutorials or examples for nwConnection AND SwiftUI. The majority of the SwiftUI networking tutorials all use URLSession, which as far as I can tell wouldn't be applicable to my situation.
If anyone has any tutorials/examples of networking connections (Host/Port) with SwiftUI that could be useful to me, I'd be really grateful for the link.
Thank you all for reading