linux ipc

Hi to all,
can u tell me theanswer of it,
1-in socket programming if we are using tcp then why thee is no bind()system call in client side,if we write bind()sys call is there any difference also this bind() system call is present in udp socket so shall i omit that bind() call in client side,i am bit confuse ,,,,,can u help me
There are two elements to a socket, the socket itself which the OS knows is part of your program and the port, which is a virtual connection to the network and is a generic part of the OS.

The bind() connects the port and the socket, it 'binds' them together which effectively tells the OS that "any messages that arrive on this port are to be passed to my socket so I can read them". This is normally done when creating a server socket that accepts incoming requests. Clients can only specify a port and network address of the server they want to connect to so it is important that the server process is connected to the correct port.



For a TCP connection the client calls connect() which attempts to establish a connection to the server. It only takes the address and port of the server you are trying to connect to. The port the client uses doesn't matter and it is left to the OS to assign the next one available. It doesn't matter because the server program doesn't need to know. The two OS's use the TCP protocol to exchange the information that establishes the connection without the user programs getting involved. connect() effectively incorporates the bind() plus some extra connection stuff.

UDP is connectionless so there is no client or server, you just bind to your local socket and fire off messages or receive incoming messages.

Hope this clears up your confusion

Bertha
Last edited on
If you just want to do IPC, the more common solution on linux is to use mmap() and avoid tying up ports.
Thats a good point, if the client and server are on the same machine, there are much easier ways of communicating between them.
OpenMP - An API for multi-platform shared-memory parallel programming in C/C++

On the same machine. Multi-threaded development is probably going to be easier.
Last edited on
Just a note. The BOOST library has a couple of good, multi-platform IPC implementations. Definitely suggest using this.
Topic archived. No new replies allowed.