Log In    |    Knowledge Base    |    4D Home
Tech Tip: Connecting with 4D Open for 4D via TCP/IP
Published On: September 10, 1999

The 4D Open for 4D Documentation leaves out an important bit of information when it comes to opening a connection to a 4D Server using TCP/IP. Under the command "OP Find 4D Server", the documentation states:

To find a server using TCP/IP, serverName should be equal to the IP address followed by a colon and the name of the database. For example, you should pass the following for a Customers DB database with the IP address " DB"

In order for this command to work properly, you will also need to supply the Port Number in the serverName string, e.g.: ",19813:Customers DB"

Please note that the port number has changed from 4D 6.0.x to 4D 6.5. The 6.0.x network components use (by default) port 14566, while the v6.5 network components use port 19813. You may copy and paste the following code to test your connection:

Cut and Paste the following code example into your
own 4D project


$Address:=",14566"  `this port is the default for the 6.0.x Network Components $Address:=",19813"  `this port is the default for the 6.5 Network Components


$TCP:=GetCompID ("TCP")  `get the ID number of the TCP/IP Network Component


$ErrCode:=OP Load network component ($TCP)

$ErrCode:=OP Find 4D Server ($TCP;sServer;iServerID)

If ($ErrCode=0)
 $ErrCode:=OP Open connection (iServerID;iConnID;"TestStation";"Administrator";"admin";"TaskName")
  If ($ErrCode=0)
   $ErrCode:=OP Close connection (iConnID)
  End if
 End if

$ErrCode:=OP Delete 4D Server (iServerID)

$ErrCode:=OP Unload network component ($TCP)