First of all you need to find actual error.you can do as follows
As bind man page
On error, -1 is returned, and errno is set appropriately.
The standard procedure in every POSIX call, there is an integer named errno that contains the value of the actual error. You can either check its value manually, or use primitives as perror or strerror
if (rc == -1)
{
perror("socket error");
}
must have #include<errno.h>
Now bind fails many reason one of it like
Probably some other application is listening on that port. You can find this by running
netstat -a | grep "18017"
So if you found port in use then switch to another port number or simply kill that process which uses that port.
Also please update you while...loop
in proper format like no need to compare rc
to both -1
and 0
please do as follows
while(1)
{
//try to receive some data, this is a blocking call
if ((rc = recvfrom(acceptSocket, buf, 256, 0, (struct sockaddr *) &client, &client)) == -1) // read datagram from server socket
{
break;
}
//rest of your code
}