Good day,
I am doing a request to a server using the following code:
try { using (var client = new WebClient()) { var parameters = "?param1=data"; string json = client.UploadString(MyConfigurations.MyURL + parameters, ""); //breaks here } } catch (Exception ex) { /* * Exception: * ----------- System.Net.WebException: Error: ConnectFailure (System call failed) ---> System.Net.Sockets.SocketException: System call failed at System.Net.Sockets.Socket..ctor (System.Net.Sockets.AddressFamily addressFamily, System.Net.Sockets.SocketType socketType, System.Net.Sockets.ProtocolType protocolType) [0x00057] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System/System.Net.Sockets/Socket.cs:181 at System.Net.WebConnection.Connect (System.Net.HttpWebRequest request) [0x000cf] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/System/System.Net/WebConnection.cs:171 --- End of inner exception stack trace --- at System.Net.WebClient.UploadDataInternal (System.Uri address, System.String method, System.Byte[] data, System.Net.WebRequest& request) [0x000a6] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/System/net/System/Net/webclient.cs:587 at System.Net.WebClient.UploadString (System.Uri address, System.String method, System.String data) [0x00054] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/System/net/System/Net/webclient.cs:868 at System.Net.WebClient.UploadString (System.String address, System.String data) [0x00011] in /Users/builder/data/lanes/4468/f913a78a/source/mono/mcs/class/referencesource/System/net/System/Net/webclient.cs:839 at (wrapper remoting-invoke-with-check) System.Net.WebClient:UploadString (string,string) */ }
It only breaks when I switch to another SSID on the WiFi and wont work until I close and open the app again.
Answers
Is the above code getting called multiple times, from elsewhere?
Also did your resolve your issue, as I am trying to debug a similar issue. But have not pinpointed any culprits in code yet.
No the problem was that, you need to ALWAYS respond after iOS handed your app control of the WiFi for the moment.
This is was my code (dumbed down, removed all the checks if it is my wifi hotspot etc. but the following code should work perfectly):
For the
Init()
code to work, you need to have the following in yourentitlements.plist
file as well as tick it when provisioning in the apple dev console:Then only will your app be able to register the handler in
init()