Unable to assign requested address, C ++ UDP sockets

The following code is from http://digitalpbk.blogspot.com/2007/10/unix-networking-sockets-udp-transmitter.html , it works fine on localhost, but when I change it to my ip, it gives an error

bind (): Unable to assign the requested address

I have been looking for a solution for several hours, so any help would be great

int main(void)
{

 struct sockaddr_in sin;
 char msg[10000];
 int ret;
 int sin_length;


 int s;

 s = socket(AF_INET, SOCK_DGRAM, 0);
 if(!s)
 {
  perror("socket()");
  return 0;
 }
 sin.sin_family = AF_INET;
 sin.sin_port = htons(65000);
 sin.sin_addr.s_addr = inet_addr("24.212.11.211"); // ---------------- This line ----------------
 if(bind(s, (struct sockaddr *)&sin, sizeof(sin)))
 {
  perror("bind()");
  return 1;
 }


 do  // I think the following might be a problem
 {
  sin_length = sizeof(sin);
  ret = recvfrom(s, msg, 10000, 0, (struct sockaddr *)&sin, (socklen_t*) &sin_length);
//Waits until a message is recieved...
  printf("Message[%s:%d] : %s\n",
  inet_ntoa(sin.sin_addr), sin.sin_port,msg);
 }
 while(msg[0]!='0');

 close(s);
 return 0;
}
+2
source share
1 answer

, IP-, , IP, . ( , ) "" → → ( → ) / , , IP-, , . , BIND TO ALL THE THINGS, 0.0.0.0.

+3

Source: https://habr.com/ru/post/1694510/