5 ms·
Don't forget the ordinary UNIX domain socket: you can think of them like TCP connections bound to 127.0.0.1 but not assigned a port number but a path name. This
by Erwin 13y ago
Don't forget the ordinary UNIX domain socket: you can think of them like TCP connections bound to 127.0.0.1 but not assigned a port number but a path name. This can be useful if you have e.g. 3 instances of the same program that needs to do some client/server work: rather than figuring out a port number assignment it can have a UNIX socket. Linux has also an extension to this mechanism, where the UNIX socket does not create a corresponding file.
In addition to doing cool things like passing open files over a UNIX socket, or credentials (your remote server can verify the UID of whoever opened the file in the other end!) the SOCK_DGRAM UNIX sockets are reliable and accept packets beyond normal UDP limits. This is useful for load balancing (you don't have to proxy your connection but can pass the new accepted socket directly to whowever is going to send data to it).
So if you want to make a simple server yet requesting/replying good size packets you can bind it to AF_LOCAL/SOCK_DGRAM, then the client calls bind() and sendto() while the server calls bind, then recvfrom() (which fills in the address of the caller) and sendto() back.
- beagle3 13y agoCan you give a link to good example code and documentation about this?
- denysonique 13y agohttp://nodejs.org/api/net.html#net_net http://nodejs.org/api/net.html#net_net provides one example, instead of binding to a host/port it listens on a UNIX socket.
- beagle3 13y agoFor people like me who were aware that this magic exists, but not how it is done: You might want to look at: http://www.normalesup.org/~george/comp/libancillary/ http://www.normalesup.org/~george/comp/libancillary/ [code] http://www.lst.de/~okir/blackhats/node121.html http://www.lst.de/~okir/blackhats/node121.html [description]