Initialize a connection

To connect to the Helix Core Server, your client application must call the Connect() method.

Initialize a connection without a password

// initialize the connection variables
// note: this is a connection without using a password
string uri = "localhost:6666";
string user = "admin";
string ws_client = "admin_space";


// define the server, repository and connection
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;


// use the connection variables for this connection
con.UserName = user;
con.Client = new Client();
con.Client.Name = ws_client;



// connect to the server
con.Connect(null);

Initialize a connection without a password that sets the application name and version

// initialize the connection variables
// note: this is a connection without using a password
// that sets the application name and version.
// This information will appear when commands are
// recorded in the server log as
// [ProgramName/ProgramVersion]
string uri = "localhost:6666";
string user = "admin";
string ws_client = "admin_space";

			
// define the server, repository and connection
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;

			
// use the connection variables for this connection
con.UserName = user;
con.Client = new Client();

			
con.Client.Name = ws_client;

			
// set the program name and version
P4.Options options = new P4.Options();
options["ProgramName"] ="MyP4API.NET_APP";
options["ProgramVersion"] ="2015.1.105.4164";

			
// connect to the server
con.Connect(options);

Initialize the connection variables for a connection using a password

// initialize the connection variables
// note: this is a connection using a password
string uri = "localhost:6666";
string user = "admin";
string ws_client = "admin_space";
string pass = "password";

			
// define the server, repository and connection
Server server = new Server(new ServerAddress(uri));
Repository rep = new Repository(server);
Connection con = rep.Connection;

			
// use the connection variables for this connection
con.UserName = user;
con.Client = new Client();
con.Client.Name = ws_client;


// connect to the server
con.Connect(null);

			
// login to the server to get credential
// (using null for options and user params)
Credential cred = con.Login(pass, null, null);

			
// get server metadata and check version
// (using null for options parameter)
ServerMetaData p4info = rep.GetServerMetaData(null);
ServerVersion version= p4info.Version;
string release = version.Major;

Initialize the connection variables using P4CONFIG

// initialize the connection variables
// note: this is a connection using P4CONFIG
// P4CONFIG needs to be set on the client machine
// and the current working directory should be
// used in the connection options
// set the program name and version
P4.Options options = new P4.Options();
options["ProgramName"] ="MyP4API.NET_APP";
options["ProgramVersion"] ="2018.4.169.1797";
// set the current working directory
options["cwd"] = System.IO.Directory.GetCurrentDirectory();


// connect to the server
con.Connect(options);

SSL connections

For information on SSL connections, refer to the TrustAndConnect method of the Connection Class.