how to solve error : Bind: Address Already in Use

hi
i have created socket program with proper IP address and port no
client side port no 1085[listen] and 1086[send]
gateway side port no 1086[listen_to_client] and 1085[send_to_client]
and port no 1087[listen_to_receiver] and 1088[send_to_receiver]
receiver side port no 1088[listen_to_client] and 1087[send_to_client]
well it works fine on client and gateway side not on receiver and gateway side it gives error on address binding.
can any one suggest why this happing so
when this bind error comes

thankx

The error is clear: The IP/port are in use.
Try to gess what, among all the ports your app uses, is the one in use.
To do so, use lsof if it's available on your system or netstat if it's not.
Regards.

Sometimes you try to bind() and have an error "Address already in use".
Someone is still handling the port. You can either wait for it to clear (a minute or so), or add code to your program allowing it to reuse the port:

int tr=1;

// kill "Address already in use" error message
if (setsockopt(listener,SOL_SOCKET,SO_REUSEADDR,&tr,sizeof(int)) == -1) {
    perror("setsockopt");
    exit(1);
}