0

我想使用 CocoaHtttpServer 在我的 iPhone 上构建一个服务器。我有这样的代码

```

 _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);

```

它适用于模拟器,记录的地址是10.134.0.97,也是我的

mac的IP,我可以通过以下方式访问模拟器中的服务器

10.134.0.97:50517. 直到现在一切正常。

但是当我在我的 iPad (iOS 12.0) 上安装该应用程序并运行该应用程序时,它

也记录IP地址 10.134.0.107,但是当我使用这个地址时

10.134.0.107:50517访问我的服务器,浏览器告诉我无法访问服务器,我已经尝试了pingin console,一切正常,那么错误的地方是什么?

4

0 回答 0