Socket and file descriptors

Carlj901 picture Carlj901 · Nov 14, 2012 · Viewed 21.9k times · Source

I'm learning about network programming in Unix and currently trying to understand the concept of socket and file descriptors. From what I have understood a file descriptor is simply a position in an array of pointers (File descriptor table?) and these pointers point to a file somewhere in memory.

Do socket descriptors share this array with file descriptors, but the pointer instead refers to a socket. Or is there something else that's only used for sockets?

Is this array unique to every application/process?

Answer

Some programmer dude picture Some programmer dude · Nov 14, 2012

Yes, sockets are also indices into the same table as files. At least for UNIX systems (like Linux and OSX), Windows is different, which is why you can't use e.g. read and write to receive and send data.

Each process has its own "file" descriptor table.