Re: what type of socket should I use?

From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 04/07/04


Date: Wed, 07 Apr 2004 11:16:41 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Rajarshi Guha wrote:

| Hi,
| I'm writing a client server type program that will always run on the
| same machine. Essentially the server just waits till it gets a message
| from the client (a seperate program) and on reciept of a message it send
| some thing back.
|
| My question is what type of socket should I use for this type of thing? I
| had though about pipe but the client and servers are not forked process -
| they will be two totally seperate programs.
|
| I also dont want to open a port using a TCP socket.
|
| I had thought of using a Unix domain socket but can this be used for thios
| situation?
|
| Could anybody suggest a direction I should follow for this problem?

Your question isn't really about "which type of socket to use". It's
more about "which type of IPC (Inter Process Communications) to use".

In general, when both client and server are executed on the same system,
you have the choice of at least
a) TCP/IP sockets, either
~ i) TCP streams,
~ ii) UDP datagrams,
b) Unix domain sockets
c) pipes
d) Named Pipes (aka FIFOs)
e) Shared Memory

You've eliminated TCP/IP sockets and pipes, so this leaves Unix domain
sockets, Named Pipes, or Shared Memory (at least)

Named Pipes are one-way, so you'd need at least two (one collected by
the server, and one collected by each client). You would have to
formalize the rendezvous technique, so that client knows the name of the
server's named pipe, and (more importantly) server knows the name of the
client's named pipe. Other than that, accessing contents of the pipe is
straightforward, and consists of the standard file I/O that works
against files.

Unix Domain Sockets is similar to Named Pipes. However, since a Unix
Domain socket is two-way, there only needs to be one. The rendesvous
technique is simplified considerably, as there is only one 'well known'
name to worry about.

Shared memory permits two programs to set aside a communications area
inside their static or heap-allocated memory. Semaphores are used to
co-ordinate access to the memory. Of the three techniques, it is likely
the most efficient, but hardest one to code for.

My suggestion would be to use Unix Domain Sockets unless you absolutely
need efficiency.

- --

Lew Pitcher, IT Consultant, Enterprise Application Architecture
Enterprise Technology Solutions, TD Bank Financial Group

(Opinions expressed here are my own, not my employer's)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (MingW32)

iD8DBQFAdBtXagVFX4UWr64RArBFAKCB15cFEA6drL8SVasl3mhL7C2jeQCg7WEH
J38OZfmCuxpdjwjJAritojk=
=WeCT
-----END PGP SIGNATURE-----



Relevant Pages

  • Re: what type of socket should I use?
    ... Essentially the server just waits till it gets a message ... | from the client and on reciept of a message it send ... sockets, Named Pipes, or Shared Memory ... Unix Domain Sockets is similar to Named Pipes. ...
    (comp.os.linux.networking)
  • Re: Delegation???
    ... EFS in Win2k relies on delegation working over named pipes, ... client and server, where the server can connect to another server as well. ...
    (microsoft.public.platformsdk.security)
  • Re: Fix of problem connecting VS2005 to remote Sql 2000 server
    ... | I'm not referring to the named pipes vs tcp when I refer to "tools", ... | I'm also a little confused, because the ISA server at the remote server ... client to use the named pipe protocol to connect to the SQL server. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: strlen() +1 in write command?
    ... "Interprocess Communications," which is can be done via named pipes if ... the processes are completely detached from each other, i.e. a server ... Client 2 sends: "World to Client 2\0" ... With that said, '\n' is as good as '\0' as a message terminator, however ...
    (comp.unix.programmer)
  • Re: communication with a daemon
    ... > to work over a network (client and server on different machines). ... I've tried with Unix Domain Sockets and the gcc extension stdio_filebuf. ... the client process is killed, the sent message from the client is printed. ... using namespace std; ...
    (comp.os.linux.development.apps)