Network connections send and receive data using transport and security protocols.

Network Documentation

Pinned Posts

Posts under Network tag

338 Posts
Sort by:
Post not yet marked as solved
12 Replies
2.3k Views
I'm trying to use Network framework for a UDP connection. It works, I get traffic flowing both ways when UDP server is responding, however when the server is down and box sends ICMP port unreachable completion blocks from nw_connection_receive_message() nw_connection_receive() are not getting called. State and viability change handlers are also not getting called. In my app console though I see message [connection] nw_socket_get_input_frames [C1:1] recvmsg(fd 4, 9216 bytes) [61: Connection refused] So somewhere inside of the API it actually gets the ICMP and knows that connection is refused, but how exactly do I get notified about this? This surely beats waiting on connection and timing out if host is nice enough to tell you that port is closed right away.
Posted
by
Post marked as solved
13 Replies
4.1k Views
Historically, one could not bind on privileged ports (1024) without using a PriviledgedHelperTool. Since macOS Mojave, it seems we don't need it anymore. Very good, but is this behavior change official and documented somewhere ? I haven't found any official information (just this link on news.ycombinator.com/item?id=18302380) Regards
Posted
by
Post not yet marked as solved
3 Replies
936 Views
Hello, For our iOS app, we're switching WebSocket client implementation from one using Poco project - https://github.com/pocoproject/poco to one based on NSURLSessionWebSocketTask. We are observing one regression which prevents us from shipping this solution though: 5-7% of calls to -[NSURLSessionWebSocketTask cancelWithCloseCode:reason:] fail to deliver given close code to server and 1006 close code (AbnormalClosure) is used instead. Our test consist of following steps: Create WebSocket using NSURLSessionWebSocketTask Send "Hello" message Close WebSocket with 1011 close code Destroy NSURLSessionWebSocketTask instance Check whether server received 1011 close code We do not perform those steps line by line, but rather use delays (~100-200ms) between each step. We perform such test 1000 times and observe 5-7% failure rate consistently. Distribution of failures is random. We did perform test on both iOS simulator and iOS devices with no observable differences. We did perform test on multiple server implementations (tornado- and node.js based ones) running on local machine (same as Xcode) and remote one We always receive "Hello" message on server 1011 close code is arbitrarily chosen for testing, but results are same for different ones, too. We did setup mitmproxy and for failed tests see following log: Error in WebSocket connection to 20.16.12.131:8080: WebSocket connection closed unexpectedly by client: TcpDisconnect(None) We did enable CFNetwork diagnostic using CFNETWORK_DIAGNOSTICS and found one difference between success and failure cases. For successful cases we see log which looks like this: default 16:27:15.831193+0200 Playground-ObjC tcp_close [C7.1:2] TCP Packets: snd 0.000s seq 1092086878:1092086879 ack 0 win 65535 len 0 [SEC] rcv 0.004s seq 3101059099:3101059100 ack 1092086879 win 65535 len 0 [S.] snd 0.000s seq 1092086879:1092086879 ack 3101059100 win 4117 len 0 [.] snd 0.002s seq 1092086879:1092087279 ack 3101059100 win 4117 len 400 [P.] rcv 0.001s seq 3101059100:3101059100 ack 1092086879 win 2058 len 0 [.] rcv 0.000s seq 3101059100:3101059100 ack 1092087279 win 2052 len 0 [.] rcv 0.015s seq 3101059100:3101059229 ack 1092087279 win 2052 len 129 [P.] ECT0 snd 0.000s seq 1092087279:1092087279 ack 3101059229 win 4113 len 0 [.] snd 0.003s seq 1092087279:1092087289 ack 3101059229 win 4113 len 10 [P.] rcv 0.002s seq 3101059229:3101059229 ack 1092087289 win 2052 len 0 [.] snd 0.017s seq 1092087289:1092087297 ack 3101059229 win 4113 len 8 [P.] snd 0.001s seq 1092087297:1092087298 ack 3101059229 win 4113 len 0 [F.] rcv 0.000s seq 3101059229:3101059229 ack 1092087297 win 2052 len 0 [.] rcv 0.001s seq 3101059229:3101059233 ack 1092087297 win 2052 len 4 [P.] ECT0 Last packet 0ms ago. So it's something related to "tcp_close" and seems to log whole TCP packets that were exchanged during connection. For failed cases such log is not present. One additional log we see potentially interesting (but were not able to confirm its meaning or relation to failed cases) comes from runningboardd: default 16:27:15.830447+0200 runningboardd Invalidating assertion 33-1364-23682 (target:[applicationorg.example.app:1364]) from originator [applicationorg.example.app:1364] So that's where we are right now and we have no idea where to dig next. We wonder if anyone else have seen such problem or can point us to any direction we could try next. Thanks much, Damian & Maciek
Posted
by
Post not yet marked as solved
11 Replies
10k Views
I have a project which has iOS 10.0 deployment target in which I import Network framework in some class and conditionally using it depending on the host app’s iOS version.   With Xcode 13 beta 4(13A5201i), I am able to compile and run the project successfully while debugging on iPhone device but it gives below error. This was working fine with Xcode 12.5.1 /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/lib/swift/Network.swiftmodule/armv7-apple-ios.swiftinterface:1254:19: 'NWConnection' is only available in iOS 12.0 or newer /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS15.0.sdk/usr/lib/swift/Network.swiftmodule/armv7-apple-ios.swiftinterface:1254:1: Add @available attribute to enclosing extension /Application/NWBrowserManager.swift:10:8: Failed to build module 'Network' for importation due to the errors above; the textual interface may be broken by project issues or a compiler bug
Posted
by
Post marked as solved
6 Replies
2.0k Views
We are building a macOS client where we make a web socket connection to our server using NWConnection. The code to to create NWParameters is: let options = NWProtocolTLS.Options() let securityProtocolOptions = options.securityProtocolOptions //....configure security options for server and client cert validation... let parameters = NWParameters(tls: options) let wsOptions = NWProtocolWebSocket.Options() wsOptions.autoReplyPing = true wsOptions.setAdditionalHeaders(additionalHeaders.map { ($0.key, $0.value) } ) parameters.defaultProtocolStack.applicationProtocols.insert(options, at: 0) With these parameters and an NWEndpoint object, we create a connection which connects and transfers data well from both sides. However, whenever server gracefully closes the connection, the client remains oblivious to this and does not close the connection. It only detects a timeout when trying to send some data over the connection after the server disconnect. We looked into Wireshark and we do not see any FIN,ACK or RST packets being received from server. However, in our windows client, when same exact server closes the connection, we are seeing FIN, ACK and connection immediately closes on client side as well. We also tried to test same behaviour in golang with a small snippet created by our team member running on Mac itself. This snippet also receives FIN,ACK from server and closes the connection immediately. Only NWConnection in our Mac client does not receive close connection. So, the question arises, why is NWConnection not receiving FIN,ACK and not closing the connection when a windows as well as a golang client on Mac is able to. Is there any extra configuration required for NWConnection or NWParameter? Is the NWParameter creation code correct? We already checked and we are continuously calling receiveMessage on the NWConnection object. So, missing read is not the issue here. Also, I do not see any connection timeout option in NWProtocolWebSocket but it exists in NWProtocolTCP. So, is there a way to set connection timeout for web socket connection using NWConnection?
Posted
by
Post not yet marked as solved
6 Replies
4.7k Views
My issue: I go through Settings>Wi-fi>The i button next to my network name>Configure Proxy>Manual. When entering my proxy's hostname, port and authentication, everything seems fine. It allows me to save the info and gives me no error prompts. However, the proxy does not actually work. The same one works perfectly when using chrome extensions to connect to it. I am 100% sure I am entering the information correctly. Questions: Does anyone else experience this issue? If so, do you know of why? If so, do you know a workaround? Device Info: iPhone Xs on iOS 15.4.1 (this issue has persisted since I first tried on 14.8, and was not fixed by installing the update.) Network Info: IP and DNS are on automatic configuration
Posted
by
Post not yet marked as solved
0 Replies
2k Views
General: TN3151 Choosing the right networking API Networking Overview document — Despite the fact that this is in the archive, this is still really useful. TLS for App Developers DevForums post Choosing a Network Debugging Tool documentation WWDC 2019 Session 712 Advances in Networking, Part 1 — This explains the concept of constrained networking, which is Apple’s preferred solution to questions like How do I check whether I’m on Wi-Fi? TN3135 Low-level networking on watchOS Adapt to changing network conditions tech talk Foundation networking: DevForums tags: Foundation, CFNetwork URL Loading System documentation — NSURLSession, or URLSession in Swift, is the recommended API for HTTP[S] on Apple platforms. Network framework: DevForums tag: Network Network framework documentation — Network framework is the recommended API for TCP, UDP, and QUIC on Apple platforms. Network Extension (including Wi-Fi on iOS): See Network Extension Resources Wi-Fi Fundamentals Wi-Fi on macOS: DevForums tag: Core WLAN Core WLAN framework documentation Wi-Fi Fundamentals Secure networking: DevForums tags: Security Apple Platform Security support document Preventing Insecure Network Connections documentation — This is all about App Transport Security (ATS). Available trusted root certificates for Apple operating systems support article Requirements for trusted certificates in iOS 13 and macOS 10.15 support article About upcoming limits on trusted certificates support article Apple’s Certificate Transparency policy support article Technote 2232 HTTPS Server Trust Evaluation Technote 2326 Creating Certificates for TLS Testing QA1948 HTTPS and Test Servers Miscellaneous: More network-related DevForums tags: 5G, QUIC, Bonjour On FTP DevForums post Using the Multicast Networking Additional Capability DevForums post Investigating Network Latency Problems DevForums post Local Network Privacy FAQ DevForums post Extra-ordinary Networking DevForums post Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com"
Posted
by
Post not yet marked as solved
4 Replies
1.6k Views
Does anyone know how to rid of this message? It is happening every time I build a project using the simulator with the following versions: xCode 13.4.1 mac Monterey 12.4. I didn't see this behavior in Xcode's previous versions. The issue seems to be because it is adding a new application every time I build the project into the firewall app list. (image below) Any tips on how to fix this?
Posted
by
Post marked as solved
3 Replies
1.7k Views
Our (legacy) code to communicate with peripherals on local IPv6 networks (LAN) adds the zone identifier / interface name ("%en0") to link-local IP addresses (FE80::/10) discovered via SSDP. SSDP is implemented using CocoaAsyncSocket - yes, that part of our code is old... (from before the introduction of the iOS 12+ Network framework). We use these modified IP addresses as the host component of a URL in a URLSession.dataTask. To insert the zone identifier we are using URLComponents (we modify the host and then request the string). This worked fine in iOS 15 and below, but no longer works in iOS 16 (Beta 1/2/3); the host is empty after inserting %en0 in the most recent beta. We have reported this via FB10549269, but from the answer it is unclear to me whether Apple is planning to fix this ("Resolution: Potential fix identified"), or we are doing it wrong. How should we handle IPv6 link-local addresses in iOS 16? (when using URLSession instead of Network) PS: We recently dropped support for iOS 12, but we still need to support iOS 13 and up
Posted
by
Post marked as solved
2 Replies
1.8k Views
I'm testing network loss handling in my app on the simulator. Turning WiFi OFF triggers pathUpdateHandler with .unsatisfied status. Turning WiFi back to ON triggers pathUpdateHandler with .unsatisfied status again. I noticed that pathUpdateHandler is triggered right after I enabled WiFi, but before WiFi actually connects to the network. When the laptop is actually connected to the WiFi network - pathUpdateHandler isn't triggered, so my app stays in "offline" mode permanently. networkMonitor.pathUpdateHandler = { [weak self] path in guard let self = self else { return } DispatchQueue.main.async { if path.status == .satisfied { self.status = .connected } else { print(path.unsatisfiedReason) self.status = .disconnected } } } monitor.start(queue: queue) networkMonitor is retained by my DIContainer
Posted
by
Post marked as solved
14 Replies
6.4k Views
IOS 16 local dns not working from router Does anyone know how to deal with it?
Posted
by
Post not yet marked as solved
10 Replies
769 Views
Description: Using the Network framework, SDDP discovery will fail while 3rd party apps are running in the background The 3rd party apps in question are (presumably) using the CocoaAsyncSocket library to perform SSDP discoveries on WiFi. How to reproduce Test Setup: For the 3rd party app, you can use https://apps.apple.com/us/app/web-video-cast-browser-to-tv/id1400866497 The simplistic test app referenced below can be installed from: https://github.com/tifroz/SSDPTest You must have the multicast entitlement (https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast) Test steps: On the test device, install a 3rd party app that uses the CocoaAsyncSocket library to performs SSDPdiscovery. Restart the test device to clear any existing 3rd party apps/processes Run this test app on the device, the status should be ready Kill the test app Start the 3rd party app that uses the CocoaAsyncSocket library, then send it to the background (without killing it) after a few seconds Start the test app, this time the status should be (failed, address already in use) Optionally, kill the test app + the 3rd party app, then start the test app again (status should be ready) Question: Is there a workaround?
Posted
by
Post not yet marked as solved
1 Replies
1.6k Views
I am trying to develop an App in Swift Playgrounds that will use the SwiftMQTT package. SwiftMQTT needs to open an outgoing network connection to connect the app to an MQTT server. To integrate the package, I wrote a basic manager class as an observable object. When I try to make a connection with this manager, Swift Playgrounds appears to block the connection. Searching around, I found that this was likely due to sandboxing but couldn't figure out how to fix it in Swift Playgrounds. To test this idea, I moved my manager class over to XTools and created a test app to make the connection. Initially, I got the same error. However, XTools let me make the needed sandbox setting on the Signing & Capabilities page of the app. Click/checkmarking "Outgoing Connections (Client)" under Network solved my problem there. I would still like to do this in Playgrounds but can't for the life of me figure out how to open up the sandbox. Can anybody point me there (or wave me off if this is currently impossible).
Posted
by
Post not yet marked as solved
3 Replies
1.7k Views
As you can see in this open source repository, I am trying to test out the code provided when you download the Apple sample "Building a custom peer-to-peer protocol" I bought a new Apple TV in order to work with this. But I have had so many issues! First I realized that the functionality is only available from WatchOS 9 or greater, but my Apple Watch 3 won't update to WatchOS 9. Then I got another watch, but it had to be updated. Then had to turn on the Developer Mode and then I was having a issues where it kept saying that the phone & watch needed to be unlocked, over and over -.-. Then finally after building the app on the watch from my computer using Xcode (latest), the problem I am now having is that the app on the AppleTV only detects the phones in the network, and not this new Apple Watch. -,- So now I just have a bunch of new technology that is doing nothing I have read through so many tutorials but can't tell why it doesn't detect it. It seems like the DDDevicePickerViewController is not returning the watch. The other question I have is, can I use the Network Framework to connect to multiple devices at the same time? (Think Texas hold em poker on Apple TV but with cards on each player's phone)
Posted
by
Post not yet marked as solved
5 Replies
1.6k Views
This is happening Mac M1 Monterey OS .Environment supports both IPv4 and IPV6. When a http client calls gettaddrinfo() it is returning both IPv6,IPv4 IPs . first v6 IPs and then v4 IPs. We need to have a way to sort gettaddrinfo() output to get v4 ip first and then v6. We tried changing DNS order with scutil by putting v4 DNS first , but still getaddrInfo() listing v6 IPs first . In linux there is a way to control gettaddrinfo() o/p with /etc/gai.conf https://man7.org/linux/man-pages/man5/gai.conf.5.html . In Mac I did not find any option like this , scutil changing order DNS is not effective . can you tell us what is way to do this in MAC OSx ?
Posted
by
Post not yet marked as solved
0 Replies
1.6k Views
This issue has cropped up many times here on DevForums. Someone recently opened a DTS tech support incident about it, and I used that as an opportunity to post a definitive response here. If you have questions or comments about this, start a new thread and tag it with Network so that I see it. Share and Enjoy — Quinn “The Eskimo!” @ Developer Technical Support @ Apple let myEmail = "eskimo" + "1" + "@" + "apple.com" iOS Network Signal Strength The iOS SDK has no general-purpose API that returns Wi-Fi or cellular signal strength in real time. Given that this has been the case for more than 10 years, it’s safe to assume that it’s not an accidental omission but a deliberate design choice. For information about the Wi-Fi APIs that are available on iOS, see TN3111 iOS Wi-Fi API overview. Network performance Most folks who ask about this are trying to use the signal strength to estimate network performance. This is a technique that I specifically recommend against. That’s because it produces both false positives and false negatives: The network signal might be weak and yet your app has excellent connectivity. For example, an iOS device on stage at WWDC might have terrible WWAN and Wi-Fi signal but that doesn’t matter because it’s connected to the Ethernet. The network signal might be strong and yet your app has very poor connectivity. For example, if you’re on a train, Wi-Fi signal might be strong in each carriage but the overall connection to the Internet is poor because it’s provided by a single over-stretched WWAN. The only good way to determine whether connectivity is good is to run a network request and see how it performs. If you’re issuing a lot of requests, use the performance of those requests to build a running estimate of how well the network is doing. Indeed, Apple practices what we preach here: This is exactly how HTTP Live Streaming works. Keep in mind that network performance can change from moment to moment. The user’s train might enter or leave a tunnel, the user might walk into a lift, and so on. If you build code to estimate the network performance, make sure it reacts to such changes. But what about this code I found on the ’net? Over the years various folks have used various unsupported techniques to get around this limitation. If you find code on the ’net that, say, uses KVC to read undocumented properties, or grovels through system logs, or walks the view hierarchy of the status bar, don’t use it. Such techniques are unsupported and, assuming they haven’t broken yet, are likely to break in the future. But what about Hotspot Helper? Hotspot Helper does have an API to read Wi-Fi signal strength, namely, the signalStrength property. However, this is not a general-purpose API. Like the rest of Hotspot Helper, this is tied to the specific use case for which it was designed. This value only updates in real time for networks that your hotspot helper is managing, as indicated by the isChosenHelper property. But what about MetricKit? MetricKit is so cool. Amongst other things, it supports the MXCellularConditionMetric payload, which holds a summary of the cellular conditions while your app was running. However, this is not a real-time signal strength value. But what if I’m working for a carrier? This post is about APIs in the iOS SDK. If you’re working for a carrier, discuss your requirements with your carrier’s contact at Apple.
Posted
by
Post not yet marked as solved
10 Replies
1.5k Views
I maintain a cross-platform client side network library for persistent TCP connections targeting Win32, Darwin and FreeBSD platforms. I recently upgraded to a Mac Studio w/ M1 Max (Ventura 13.1) from a late 2015 Intel Macbook Pro (Monterey 12.6.2) and I've encountered a discrepancy between the two. For secure TCP connections my lib uses WolfSSL across all platforms but also supports use of system provided Security libraries. On Darwin platforms this is SecureTransport. Yes I am aware SecureTransport is deprecated in favor of Network. I intend to attempt to integrate with Network later but for now my architecture dictates that I use similar C-style callbacks akin to WolfSSL, OpenSSL, MBedTLS etc. On the first call to SSLHandshake the SecureTransport write callback generates 151 bytes for my TLS 1.2 connection to example.com:443 on both platforms. However, while on Intel MBP I am able to continue with the full handshake I immediately receive 0 bytes with EOF. In Wireshark on the Intel MBP the 151 bytes are observed as a TLS 1.2 client hello while on M1 it is observed as an SSL continuation message and that is the last message observed.
Posted
by
Post not yet marked as solved
3 Replies
1.5k Views
Hi everyone, my app search tv in same networking and this stopped working after updating my ios version to 16. My app have networking.multicast property in info.plist and I followed the guide to discover other devices on the same network and including i got apple permission to multicast https://developer.apple.com/documentation/bundleresources/entitlements/com_apple_developer_networking_multicast When i test the app in devices with ios 14 and 15 working perfectly. someone had this problem?
Posted
by
Post not yet marked as solved
5 Replies
1.6k Views
Hi, I want to force my app to use wifi for it to work. For that im using the en0 interface. It works fine,but does an iphone always use this interface. In my case, should I check en1 and en2 interfaces for wifi ?
Posted
by
Post not yet marked as solved
17 Replies
2.1k Views
I am working on a XCTest UI test automation and I want to add the ability to communicate with a test hub on our local network that controls external test equipment that is being used to create test conditions that are external to the IPAD. Currently when I run the test on the simulator running on a MAC mini it works fine and communicates with the external machine but if I run on target which is a 6th Get IPAD it receives "POSIXErrorCode(rawValue: 50): Network is down" I have tried to add permissions to the test bundle to allow this to work but nothing seems to fix it. I am a novice when it comes to IOS development in general so maybe I am missing something obvious. I thought that this https://developer.apple.com/forums/thread/668729 solution would fix my problem but adding the permissions didn't help. I am using Xcode 13.4.1, the IOS on the target is version 15.5.
Posted
by