0

I want to use CocoaHtttpServer to build a server on my iPhone. and I have the code like this

```

 _httpServer = [[HTTPServer alloc] init];
[_httpServer setPort:50517];
[_httpServer setType:@"_http._tcp."];

NSString *webResourcePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:@"web"];
[_httpServer setDocumentRoot:webResourcePath];
[_httpServer setConnectionClass:[MyHTTPConnection class]];
NSError *err;
if([_httpServer start:&err]){
     NSLog(@"start server success in port %d %@",[_httpServer listeningPort],[_httpServer publishedName]);
}else{
    NSLog(@"%@",err);
}
NSString *ipStr = [LGUtils getIpAddresses1];
NSLog(@"ip address : %@",ipStr);

```

It works on simulator, the logged address is 10.134.0.97, also it's my

mac's IP, I could access the server in the simulator by

10.134.0.97:50517. Until now everything was working normally.

But when I installed the app in my iPad (iOS 12.0), and I run the app, it

also log the ip address 10.134.0.107, but when I use this address

10.134.0.107:50517 to access my server, the browser tells me that I can't access the server, I have try the ping in console, every thing is ok, so what's the wrong place?

  • 1
    Check if this helps https://stackoverflow.com/a/40299837/656600 – rptwsthi Nov 21 '18 at 11:23
  • @rptwsthi Thanks for that, I have configured the `Allow Arbitrary Loads` to YES, It works on simulator but not device, if the configuration has something wrong, it couldn't works on simulator, right? – guodada1206 Nov 22 '18 at 01:33

0 Answers0