Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa client/server application

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.

like image 289
hashemi Avatar asked Jan 03 '09 16:01

hashemi


3 Answers

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.

like image 120
Barry Wark Avatar answered Sep 28 '22 09:09

Barry Wark


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.

like image 45
Marc Charbonneau Avatar answered Sep 28 '22 08:09

Marc Charbonneau


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

like image 45
mmx Avatar answered Sep 28 '22 09:09

mmx