Connect Function

Action

Establishes a connection to the specified machine.

Syntax

hMachine = Connect ([sMachine, [sAgentType]])
Variable Description
hMachine A handle to the machine. HMACHINE.
sMachine

Optional: The name of the machine to connect to. STRING.

For TCP/IP networking only: If you specify a machine name, Silk Test Classic connects using the default port number, 2965 for the Classic Agent or 48561 for the Open Agent. However, you can specify a port number by using a colon separator after the machine name. For example, enter mymachine:5592 to connect to mymachine through port number 5592. If the port is in use or invalid, no error is reported and the default port is used instead.

If you do not specify a machine name, Silk Test Classic returns local host or the host name specified in the Runtime Options dialog box.

sAgentType

Optional: The type of agent that you want to connect to. The allowed values are CLASSIC_AGENT and OPEN_AGENT.

If you do not specify an Agent, Silk Test Classic uses the default agent type.

Notes

  • Connect connects the running 4Test script to machine sMachine. This machine becomes the current machine. Silk Test Classic raises the exception E_AGENT if the connection cannot be made.

  • Connect establishes a link using the Silk Test agent type specified using sAgentType on sMachine. Function calls are made to the agent on sMachine which is not necessarily the machine where the script is running.

  • Connect establishes a link using the Silk Test agent type specified using sAgentType on sMachine. Function calls are made to the agent on sMachine which is not necessarily the machine where the script is running.

  • Your code should store the HMACHINE handle returned by Connect so that other distributed functions can use it later.

  • Do not use the Connect function to specify a NetBIOS adapter number; if you do, Silk Test Classic ignores this value. The NetBIOS adapter number is read by the value you set in the Network text box on the Runtime Options dialog box.

  • If you call a method on a window declaration, the window declaration determines the agent type, not the Connect function. The Silk Test agent type specified in a window declaration always overrides the agent type specified in the Connect function.

Examples

The following example illustrates the use of HMACHINE to print data from the host machine and target machine.

HMACHINE target_machine // target computer
HMACHINE host_machine // host computer
STRING sTarget = "sunfish" // target's network name
STRING sHost = "moonray" // host's network name
// save host’s handle
host_machine = GetMachine ()
// save target's handle
target_machine = Connect (sTarget)
// what is currently active on the target machine?
Print ("Active window on Target: ",Desktop.GetActive ())
// switch to host machine
SetMachine (host_machine)
// what is currently active on host machine?
Print ("Active window on Host: ",Desktop.GetActive ())
Disconnect (target_machine) // disconnect from target

The following example illustrates the use of sAgentType to create a script that uses the Classic Agent, Open Agent, or the default agent.

[-] testcase mytestcase()
	[ ] HANDLE hOpenAgent, hClassicAgent
	[ ] // this executes against the default agent, which is set in the Runtime dialog
	[ ] SomeAgentFunction1()
	[ ] // this connects to the Open Agent on a remote/local machine
	[ ] hOpenAgent = Connect("agentmachine", OPEN_AGENT)
	[ ] // this executes against the Open Agent
	[ ] hOpenAgent->SomeAgentFunction1()
	[ ] // this connects to the Classic Agent on a remote/local machine
	[ ] hClassicAgent = Connect("agentmachine",CLASSIC_AGENT)
	[ ] // this executes against the Classic Agent
	[ ] hClassicAgent->SomeAgentFunction1()