This has been a big trouble to people.
There can be many causes for this error.
To detect any error in networks, use perror() function. This function will tell the error based on the error number (errno) set by the recently called function.
After calling the bind() function, and checking the return value as -1, you would have used perror() to print the error. Mostly you would have seen the perror() printing : "Address already in use". This is caused by some unexpected closing of the server program and client program, when you executed it the last time. This is because of some concept of connection termination which is a 4 - way handshake.
The "address" in the error, refers to the socket address. Socket address is a combination of port address and ip address. "Address already in use". The ip address is not being used by anyone, but the port address can be open because of the unexpected closing, that I mentioned. So, now you got to check for open ports. And you will have to change the port number in your program.
To check if the port used in your program is in use, try this statement
netstat -tulpn | grep <port number>
for eg
netstat -tulpn | grep 5678
you can use an extra option -a
netstat -tulpn -a | grep 5678
And other causes for bind error may be because of undefined socket descriptor.
May be you didn't check the socket descriptor value, and may be it's value is -1, because of some error in socket() system call. So, when you use this invalid socket descriptor value in bind() function as argumnet, you will get errors.
If you still have other related problems, just comment.
There can be many causes for this error.
To detect any error in networks, use perror() function. This function will tell the error based on the error number (errno) set by the recently called function.
After calling the bind() function, and checking the return value as -1, you would have used perror() to print the error. Mostly you would have seen the perror() printing : "Address already in use". This is caused by some unexpected closing of the server program and client program, when you executed it the last time. This is because of some concept of connection termination which is a 4 - way handshake.
The "address" in the error, refers to the socket address. Socket address is a combination of port address and ip address. "Address already in use". The ip address is not being used by anyone, but the port address can be open because of the unexpected closing, that I mentioned. So, now you got to check for open ports. And you will have to change the port number in your program.
To check if the port used in your program is in use, try this statement
netstat -tulpn | grep <port number>
for eg
netstat -tulpn | grep 5678
you can use an extra option -a
netstat -tulpn -a | grep 5678
And other causes for bind error may be because of undefined socket descriptor.
May be you didn't check the socket descriptor value, and may be it's value is -1, because of some error in socket() system call. So, when you use this invalid socket descriptor value in bind() function as argumnet, you will get errors.
If you still have other related problems, just comment.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.