KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Connecting with 4D Open for 4D via TCP/IP
PRODUCT: 4D | VERSION: | PLATFORM:
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 192.9.200.13: "192.9.200.13:Customers DB"

In order for this command to work properly, you will also need to supply the Port Number in the serverName string, e.g.: "192.9.200.13,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

C_STRING(80;sServer;Database;$Address)
C_LONGINT($TCP;$ErrCode;iServerID;iConnID)

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

$Database:="Connect4D2.4DB"+Char(9)+"SQL_STATION2"

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

sServer:=$Address+":"+$Database

$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)