Cocoa 客户端/服务器应用程序

发布于 2024-07-10 22:03:54 字数 467 浏览 6 评论 0 原文

Cocoa 中是否有一种方法目前被认为是创建多层或客户端服务器应用程序的最佳实践?

我是一名经验丰富的 Web 开发人员,我非常喜欢 Python。 不过我对可可还很陌生。 我正在编写的应用程序是一家大型医院的患者管理系统。 随着时间的推移,系统预计会存储大量数据,但单个会话期间传输的数据非常少(大部分只是文本)。 假定通信通过本地网络(有线或无线)进行。 当然,它必须高度安全。

我能想到的最好办法是编写一个 Python REST Web 服务并通过 Cocoa 应用程序连接到它。 也许我什至会使用 Python 来编写 Cocoa 应用程序本身。

看看 Cocoa,我在 Cocoa 中看到了非常出色的技术,比如 CoreData,但我找不到任何类似的客户端服务器开发技术。 我只是想确保我没有遗漏任何东西。

你怎么认为?

现实世界的例子将不胜感激。

提前致谢。

Is there a way in Cocoa that is currently considered best practice for creating a multi-tier or client server application?

I'm an experienced web developer and I really love Python. I'm new to Cocoa though. The application I'm toying with writing is a patient management system for a large hospital. The system is expected to store huge amounts of data over time but the data transferred during a single session is very light (mostly just text). The communication is assumed to occur over a local network (wired or wireless). It has to be highly secure, of course.

The best I could come up with is to write a Python REST web service and connect to it through the Cocoa app. Maybe I'll even use Python to code the Cocoa app itself.

Looking at Cocoa, I see really great technologies in Cocoa like CoreData but I couldn't find anything similar for client server development. I just want to make sure that I'm not missing anything.

What do you think?

Real world examples will be greatly appreciated.

Thanks in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

深海少女心 2024-07-17 22:03:54

如果您可以控制客户端和服务器,并且可以将客户端限制为仅限 OS X,那么我支持 Marc 的回答。 Cocoa 的分布式对象是一项令人惊叹的技术,它使 RPC 风格的客户端-服务器应用程序变得非常简单。

如果上述要求对您来说限制太大,那么在 Cocoa 世界中您仍然有许多选择:

  1. 您可以使用 PyObjC 在 Python 中编写整个客户端应用程序。 通过这种方法,您可以使用 Python 标准库中您熟悉的标准网络代码。 Twisted 还与 Cocoa 运行循环(PyObjC 示例代码中的示例)很好地集成,并且我使用它取得了很多成功Twisted 用于 Cocoa 应用程序中的网络通信。 如果您选择走这条路,您可能需要使用 Objective-C 编写客户端应用程序并将 python 代码作为插件加载(使用 NSBundle)。 PyObjC 的 py2app 可以从 Python 代码编译可加载包。

  2. 您可以使用 NSURLConnection 对基于 HTTP 的服务器进行高级访问。

  3. 降低抽象级别,您可以使用 Cocoa 的 NSStream 来实现您的网络协议。 类文档是 此处,包含演示 HTTP 和 SOAP 协议的示例代码的链接。

  4. 您可以进一步降低级别并使用 CFNetwork 类。 NSStream 基于 CFNetwork,但您可以使用 CFNetwork 对线路进行较低级别的控制。

最后,用于客户端-服务器架构的 Apple 技术是 WebObjects 框架。

If you have control of both the client and server, and you can limit the client to OS X only, I second Marc's answer. Cocoa's distributed objects are an amazing technology and make RPC-style client-server apps very easy.

If the requirements above are too restrictive for you, you still have many options available to you in the Cocoa world:

  1. You can code the entire client app in Python using PyObjC. With this approach, you can use the standard network code that you're familiar with from the Python standard library. Twisted also integrates nicely with the Cocoa run loop (examples in the PyObjC example code) and I've had a lot of success using Twisted for network communication from with in a Cocoa app. If you choose to go this route, you may want to code the client app in Objective-C and load the python code as a plugin (using NSBundle). PyObjC's py2app can compile loadable bundles from python code.

  2. You can use NSURLConnection for high-level access to an HTTP-based server.

  3. Dropping down a level of abstraction, you can use Cocoa's NSStream to implement your network protocol. The class documentation is here, with links to example code demonstrating HTTP and SOAP protocols.

  4. You can drop a further level down and use the CFNetwork classes. NSStream is based on CFNetwork, but you have lower-level control over the line using CFNetwork.

Finally, the Apple technology for client-server architectures is the WebObjects framework.

嘿哥们儿 2024-07-17 22:03:54

Cocoa 有可移植分布式对象,它可以让你用纯 Objective-C 构建客户端/服务器应用程序Cocoa 可以跨进程或跨网络进行通信。

不幸的是,这是 Cocoa 中最难学习的事情之一。 分布式对象尚未更新以跟上绑定等新技术,也没有大量示例或文档(许多教程都很旧,有些甚至早于 OS X)。 即使对于经验丰富的 Cocoa 程序员来说,对象作为副本或代理对象通过网络传输的方式也存在很多“陷阱”。 例如,您可以从服务器传输 NSURL,如果您将其转换为字符串或在调试器中查看它似乎没问题,但如果您尝试在 NSURLConnection 中使用它,您的客户端将会崩溃。

根据您的经验,使用 Web 服务可能会更容易、更快捷,但如果您想将整个项目保留在 Cocoa 中,它仍然值得考虑。 如果您想查看示例,请参阅教程

Cocoa has Portable Distributed Objects, which let you build a client / server application in pure Objective-C and Cocoa which can communicate across processes or across a network.

Unfortunately it's one of the harder things to learn in Cocoa. Distributed objects haven't been updated to keep up with new technologies like bindings, there's not a lot of examples or documentation (and many of the tutorials are old, some even pre-dating OS X). There's also a lot of "gotchas," even for experienced Cocoa programmers, in the way objects are transmitted across the wire either as a copy or a proxy object. For example, you can transmit an NSURL from a server and it will seem fine if you convert it to a string or look at it in the debugger, but your client will crash if you try to use it in an NSURLConnection.

Depending on your experience it may be easier and quicker to use a web service, but it's still worth looking in to if you'd like to keep the entire project in Cocoa. Here's a tutorial if you'd like to see an example.

这个俗人 2024-07-17 22:03:54

一般来说,所有其他客户端/服务器框架的思想都是适用的。

看一下这个链接: http://developer.apple.com/internet/webservices /webservicescoreandcfnetwork.html

Generally, the ideas of all other client/server frameworks are applicable.

Take a look at this link: http://developer.apple.com/internet/webservices/webservicescoreandcfnetwork.html

孤君无依 2024-07-17 22:03:54

我已经编写了一个在 Cocoa 中使用的服务器和客户端类。
使用这些类可以很容易地生成服务器或客户端应用程序,而无需了解套接字和 C 语言知识
只需查看我的网站sourceforge.net 项目站点

I have written a server and a client class for use in Cocoa.
Using these classes makes it very easy to produce a server or client application without the knowledge about sockets and that C-stuff
Just have a look at my website or at the sourceforge.net project site.

提笔书几行 2024-07-17 22:03:54

查看 NSConnection 的 api和 NSDownload 来处理网络联系。 NSString 类也有方法就像 + stringWithContentsOfURL:encoding:error: 可能有用。

然后是 NSXMLParser 和 < a href="http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSXMLDocument_Class/Reference/Reference.html" rel="nofollow noreferrer">NSXMLDocument 用于读取 xml 数据。

Look at the api's for NSConnection and NSDownload to handle the network connection. The NSString class also has methods like + stringWithContentsOfURL:encoding:error: that may be useful.

Then there is NSXMLParser and NSXMLDocument for reading xml data.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文