KNOWLEDGEBASE
Log In    |    Knowledgebase    |    4D Home
Tech Tip: Utility method to set an IP address for Web Server to listen on
PRODUCT: 4D | VERSION: 12 | PLATFORM: Mac & Win
Published On: November 3, 2011

It is common for a computer to have more than one IP addresses assigned to it. This means that a request can be made to any of the IP addresses. However, it is possible to force 4D to listen only to one specific IP address to the machine. Here is a method force that 4D Web Server to listen on specific IP address.

  // Method: SET_LISTENING_IP
  // Parameters:
  // $1 - IP address (e.g. "120.64.0.111")
C_TEXT($1;$ip_address_t)
C_TEXT($a_t;$b_t;$c_t;$d_t)
C_LONGINT($address_l;$pos_l)

If (Count parameters>=1)
  $ip_address_t:=$1

  $pos_l:=Position(".";$ip_address_t)
  If ($pos_l>0)
    $a_t:=Substring($ip_address_t;1;$pos_l-1)
    $ip_address_t:=Delete string($ip_address_t;1;$pos_l)
  End if

  If ($a_t#"")
    $pos_l:=Position(".";$ip_address_t)
    If ($pos_l>0)
      $b_t:=Substring($ip_address_t;1;($pos_l-1))
      $ip_address_t:=Delete string($ip_address_t;1;$pos_l)
    End if
  End if
  If ($b_t#"")
    $pos_l:=Position(".";$ip_address_t)
    If ($pos_l>0)
      $c_t:=Substring($ip_address_t;1;($pos_l-1))
      $ip_address_t:=Delete string($ip_address_t;1;$pos_l)
    End if
  End if

  If ($c_t#"")
    $d_t:=$ip_address_t
  End if

  If ($d_t#"")
    STOP WEB SERVER
    $address_l:=(Num($a_t) << 24) | (Num($b_t) << 16) | (Num($c_t) << 8) | Num($d_t)
    SET DATABASE PARAMETER(IP Address to listen;$address_l)
    START WEB SERVER
  End if
End if

Commented by Add Komoncharoensiri on December 22, 2011 at 1:08 PM
You are right Peter. Apparently the commands were swapped by accident. It has been corrected now.
Commented by Peter Schumacher on November 5, 2011 at 3:06 AM
Very interesting!
Just a little thing - it makes me wonder how it works after the STOP WEB SERVER.