Question

I'm studying the Low-Level File Management Programming Topics from Apple. In the NSFileHandle section, they say:

The scope of NSFileHandle is not limited to files. It provides the only Foundation object that can read and write to communications channels such as those implemented by sockets, pipes, and devices.

That sounds GREAT! So I can talk via NSFileManager to an socket, which then transfers that data to an webserver where I mess around in a file directly, by remote?

Can someone give some easy to understand examples what I could do with this,

  • when communicating with an "Socket"?
  • when communicating with an "Pipe"?
  • when communicating with an "Device"?

Note: I don't know anything really about Sockets, Pipes, Devices. And I am sure by Devices they don't mean the iPhone itself. I'm not familiar with networking things. But I want to learn that stuff!! Maybe you could also give a short explanation what these things are?

Was it helpful?

Solution

Socket is an asset you use to communicate over network. When application wants to do any networking communication, it needs to connect to destination host. For this a socket is used. In most cases TCP/IP networking protocol is used. This requires you to specify an IP address or hostname where to connect to, and so called TCP port - that is a unique identification of service running on target host, for example 80 is used for HTTP. When connection is established, you use socket in a similar way as file handle, you simply write some data into it, or read from it. That's how networking usually works.

Pipe is a facility coming from Unix - remember, Mac and iPhone are based on Unix systems. It is (kind of arcane, but still popular) way of communication between two processes. From programming point of view, it is similar to file handle - when two processes are connected via pipe, they can write and read into pipe to communicate between each other.

Device is an abstraction of, well, a device. Imagine you want to have a direct access to your hard-drive. The way it is done on Unix systems is that you open some special file, which in fact is not a file, but it is created on filesystem as a "device". Check directory "/dev/" on your Mac, it contains available devices. For a hard-drive you can find "/dev/disk0", for its first partition "/dev/disk0s1". These "devices" represent device drivers loaded in kernel. Kernel extensions (e.g. drivers) can provide such device to enable communication with user-space programs.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top