简体   繁体   English

Xcode/Swift 中的简单本地主机服务器?

[英]Simple Localhost Server in Xcode/Swift?

I am making a macos app in XCode, and I was wondering if there was a way to make it host a local server that is visible across the network.我正在 XCode 中制作一个 macos 应用程序,我想知道是否有办法让它托管一个在网络上可见的本地服务器。

I am trying to find a way so that it would host something on the devices's network with it's hostname/ip address, so if someone goes to http://hostname:5000 they would be able to see the response, and the app would be able to see the request, just like how hosting a local python server works.我正在尝试找到一种方法,以便它使用主机名/IP地址在设备的网络上托管一些东西,所以如果有人去http://hostname:5000他们将能够看到响应,并且应用程序将是能够看到请求,就像托管本地 python 服务器的工作方式一样。 Is there any way to do this in XCode with Swift?有没有办法在 XCode 和 Swift 中做到这一点?

For example: the user presses 'start server' on their screen.例如:用户在他们的屏幕上按下“启动服务器”。 The server is hosted across the network.服务器托管在网络上。 Anytime a request is made to it, they get a notification.每当向它提出请求时,他们都会收到通知。

Just to make you concern you may find some sample codes, including local web server inside the app.Few of them I found are:只是为了让您担心,您可能会在应用程序中找到一些示例代码,包括本地 web 服务器。我发现其中很少有:

https://github.com/ooper-shlab/MyWebViewApp-Swift https://github.com/ooper-shlab/MyWebViewApp-Swift

https://github.com/depoon/SwiftLocalhost https://github.com/depoon/SwiftLocalhost

The main thing is it's just a public, experimental code, so it's not simple, not easy to adopt, not all coding best-recommended, far from readable and may have severe bugs.But you can use it as a working example and take any parts of it into your app.最主要的是它只是一个公开的、实验性的代码,所以它并不简单,不容易采用,并不是所有的编码都是最佳推荐的,远不可读,并且可能有严重的错误。但是你可以将它作为一个工作示例并采取任何它的一部分到您的应用程序中。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM