Re: what type of socket should I use?
From: Lew Pitcher (Lew.Pitcher_at_td.com)
Date: 04/07/04
- Next message: Jan Panteltje: "Re: mouse vs. keyboard"
- Previous message: WTH: "Re: IDE for C: KDevelop vs Emacs vs Other"
- In reply to: Rajarshi Guha: "what type of socket should I use?"
- Next in thread: Kasper Dupont: "Re: what type of socket should I use?"
- Reply: Kasper Dupont: "Re: what type of socket should I use?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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-----
- Next message: Jan Panteltje: "Re: mouse vs. keyboard"
- Previous message: WTH: "Re: IDE for C: KDevelop vs Emacs vs Other"
- In reply to: Rajarshi Guha: "what type of socket should I use?"
- Next in thread: Kasper Dupont: "Re: what type of socket should I use?"
- Reply: Kasper Dupont: "Re: what type of socket should I use?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|