Error when connecting Rosbridge (Web Sockets) - ios

I am developing an app for iOS with Swift 3, this application search with the Bonjour service some robots in the local network which use a specific service, for example robot.local and show them in a list. The Bonjour service gives me the domain of the device. This is a example of the domains searched.
Ex.:
robot1.local
robot2.local
The next step, is when the user click an element of the list. This action start a connection by web sockets with the device and connect it for control it with the Iphone. I am using a library called RBManager which use RocketSocket library for connect. This library helps me to connect to RosBridge.
I use this code for connect:
NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"wss://192.168.0.100:9090"]];
self.socket = [[SRWebSocket alloc] initWithURLRequest:request];
self.socket.delegate = self;
[self.socket open];
The problem is when I am install the app by Xcode I have not any problem but when I am install the app by an ipa file or by TestFlight the connection is rejected and shows this error:
managerDidFailWithError Optional(ErrorDomain=NSOSTatusErrorDomain
Code=-9807 "(null)" UserInfo={_kCFStreamErrorDomainKey=3,
_kCFStreamErrorCodeKey=-9807})
I found this issue in the library but is not the solution that I need.
I am deactive ATS in the info.plist but I not know how to solve this error. Could anyone help me?

I found the problem. The problem was that my RosBridge backend run with TLS and I didn't implement it.
The solution is implement the authentication in the client and all works :D

Related

Self-hosted Signal iOS is unable to connect to internet

same issue, other person: https://github.com/signalapp/Signal-iOS/issues/2282
We've checked out the Signal-iOS repository and we're trying to make it connect to another server. We're running an instance of the server at signal.appcraft.nl. We've modified the defines in SignalServiceKit/src/TSConstants.h to match our server and we've changed the domains in App Transport Security Settings in /Signal/Signal-Info.plist
We also cloned the Android app and that one we managed to got working just fine. The iOS app seems not to be able to connect to the internet at all without a clear error. The first HTTP call that is done is GET https://signal.appcraft.nl/v1/accounts/sms/code/<MYNUMBER>?client=ios. When we invoke that URL using curl, we get a response (and SMS) just fine. From the app, we receive a Signal was unable to connect to the internet. Please try from another WiFi network or use mobile data. error. We also changed NSAllowsArbitraryLoads to Yes.
We've added a breakpoint in /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
# /Signal-iOS/Pods/AFNetworking/AFNetworking/AFHTTPSessionManager.m:292
(lldb) expr error
(NSURLError *) $3 = 0x00000001c0244800 domain: #"NSURLErrorDomain" - code: 18446744073709550617
Please advise

How to create an HTTPS server on IOS using cocoaHTTPServer?

I made a javascript cloud app that runs on a webpage in a webview on my iPad app that communicates via WebSocket connection but it only works when im on my http site and not https or else I get an CFNetwork SSLHandshake failed (-9806) error in Xcode and on the website it says time out during handshake.
Is this because the webserver on the iPad is running on HTTP instead of HTTPS?
JAVASCRIPT CLOUD APP
This part in the cloud is working for HTTP when connecting to the web server on the iPad.
var protocol = "ws";
if (this.useSecureConnection)
protocol = "wss";
var url = protocol+'://localhost:'+this.port+'/service';
this.connection = new WebSocket(url);
Xcode iOS iPad App (Objective-C)
I thought that was the issue so I tried to enable HTTPS but I am not sure what to create for the "sslIdentityAndCertificates" method.
- (BOOL)isSecureServer
{
HTTPLogTrace();
// Override me to create an https server...
return YES;
}
/**
* This method is expected to returns an array appropriate for use in kCFStreamSSLCertificates SSL Settings.
* It should be an array of SecCertificateRefs except for the first element in the array, which is a SecIdentityRef.
**/
- (NSArray *)sslIdentityAndCertificates
{
HTTPLogTrace();
return nil;
}
Some of the other posts I have seen use APIs that are only available on Mac and not iOS.
I tried several combinations of ATS permissions as well. All resulted in HTTPS not allowing for WebSocket connection.
Any help is greatly appreciated! :)

NSURLRequest on iOS vs OS X

Is there any difference between NSURLRequest class on Mac OS and iOS?
Apparently there is one.
Here how the class description looks on Mac OS:
<NSURLRequest: 0x60000000f290> { URL: http://www.google.com/ }
And here how it looks on iOS:
<NSURLRequest http://www.google.com/>
As it appears there is a big difference for my project as it work perfectly on iOS and connection fails for Mac OS version.
Does anyone know how to make Mac OS app init the NSURLRequest class object exactly the way it does for iOS?
UPD 1
Same code for initialisation of the object for both platforms
NSURLRequest* aRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:#"http://www.google.com/"]];
I tried same to use NSURLRequest in both AFNetworking and NSURLConnection getting same result - successful connection on iOS and 403 error for Mac OS
successful connection on iOS and 403 error for Mac OS
403 is HTTP's Forbidden response. The fact that you're getting a 403 means that a) your request is making a proper HTTP connection, but b) the server doesn't want to talk to you for some reason. A good strategy for diagnosing the issue is to use a proxy like Charles to look at the successful and unsuccessful requests and note the differences. The user agent parameter is one thing that's likely to differ between the two platforms, but you'll probably find other differences as well. Once you know what's different between the two requests, you'll have a better idea of what you need to change to make the failing requests work.

iOS - Simple SSL socket connection

What is the correct way to create a SSL socket connection in iOS?
I've implemented a SSL server in Java by:
creating a SSL certificate with a store password
loading it by setting the system properties "javax.net.ssl.keyStore" and "javax.net.ssl.keyStorePassword"
creating a SSLServerSocket with the SSLServerSocket factory
Now I want to create a client app which opens a socket connection in a thread and communicates over that. What is the proper way to create such a connection and do the communication with my servers certificate?
You can use NSInputStream and NSOutputStream to connect using TLS as per the answer to this question.
EDIT:
Rather than use the SSL settings in that answer, I would suggest this:
NSDictionary *settings = #{
(__bridge NSString *)kCFStreamPropertySocketSecurityLevel:(__bridge NSString *)kCFStreamSocketSecurityLevelNegotiatedSSL
};
This uses the following defaults:
kCFStreamSSLAllowsExpiredCertificates: NO
kCFStreamSSLAllowsAnyRoot: NO
kCFStreamSSLValidatesCertificateChain: YES
If you want to set the security level to use a particular version of SSL or TLS, take a look at the values in CFSocketStream.h.
There is no need to create a certificate if you are making a client app not a server one.
To do it in iOS, there are a number of ways, the simplest is to use AFNetworking library.
Just put the url (https) inside one of its methods, and you are ready.
I used it many times. Just spend 5 mins to read the doc.

Getting the HostName of a Remote iOS Device with NSNetService

After more than a few hours of searching, I got in what looks like a dead end. In this case, all that I am trying to do, is to get all the iOS Devices of the network with Bonjour. I did so like this
self.serviceBrowser = [[NSNetServiceBrowser alloc] init];
[self.serviceBrowser setDelegate:self];
[self.serviceBrowser searchForServicesOfType:#"_apple-mobdev2._tcp." inDomain:#"local."];
This works fine, though what I get is the following:
local. _apple-mobdev2._tcp. [MAC ADDRESS HERE]
I tried to resolve the connection by using the sync port (62078), since service.port returns -1.
for (NSNetService *service in self.services) {
NSLog(#"%#", service);
NSNetService *newService = [[NSNetService alloc] initWithDomain:service.domain type:service.type name:service.name port:62078];
[newService setDelegate:self];
[newService resolveWithTimeout:30];
}
This in its own turn calls netServiceWillResolve: with no problem at all, but, it doesn't make it to netServiceDidResolveAddress:
But neither does this fail. netService:didNotResolve: isn't called either, I believe it is just waiting for a response to be resolved.
To support this claim, once it did make it to the method and actually [service hostName]; did return Yanniss-iPhone, but that happened at a completely random time that I had left the Mac App running for around half an hour. What could have invoked this to run? Or does anyone know of a different way to get the hostName of the remote device? The other answers do not answer my question, since I am looking for the hostName of the remote device, not of the Mac device.
Relative to that, I've found that when you kill and restart iTunes, along with iTunes Helper, the very log I mentioned below is sent again. Which is why I believe the correct log was an iTunes related event. Any help is very much appreciated!
iTunes search bonjour for wifi sync capability. As for the didNotResolve or resolve delay, bonjour services randomly cast itself anywhere between a few seconds to 30 minutes.
I am actually trying to connect to iOS devices too, but I could not get any response or any devices returned. :\

Resources