Before you can communicate using a JMP connection, you first need to establish the connection. To do this, you need to define connection settings using the 'Connection Properties' object.
The 'Connection Properties' object allows you to define a connection's IP Address, Port number, Login Credentials, and if it should reconnect after the conection is lost. Settings you don't enter for the connection properties will use default values. You always need to provide an IP Address, but port 9220 is the default port, and 'jnior, jnior' (Admin Role) are the default login credentials. The connection is set to reconnect by default as well.
The Connection Properties structure is used to hold connection options. This structure is created by the user program and passed to the Create Connection method.
/*** @param ip_address ip address of the target jnior* @param port jmp protocol port. 9220 by default* @param username The username to use for the initial authentication. The default "jnior" will be used if one is not provided.* @param password The username to use for the initial authentication. The default "jnior" will be used if one is not provided.* @param reconnect this connection will try to reconnect if the connection is lost. This, by default, is true* @param timeout_sec timeout in seconds. 5 seconds by default*/JMPLIB_EXPORTstructconnection_properties{conststd::stringip_address;constintport=9220;constinttimeout_sec=5;boolreconnect=true;std::stringusername="jnior";std::stringpassword="jnior";};
Here is an example of how to define values for the Connection Properties object:
// define a connection that will be successfulconstexpripg::connection_propertiesconnection_props={.ip_address=const_cast<char*>("10.0.0.63"),.port=9220};// instantiate a connectionipg::create_connection(&connection_props,uuid);// wait for the connection result. we will expect this to be successfulconstintconnection_result=ipg::wait_for_connection(uuid);autostatus_description=newchar[32];ipg::get_connection_status_description(uuid,status_description);std::cout<<std::format("connection_result: ({}) {}",connection_result,status_description)<<std::endl;// clean updelete[]status_description;if(ipg::CONNECTED!=connection_result){thrownewstd::runtime_error("Connection result was not SUCCESSFUL");}// get the connection stateintconnection_status=ipg::get_connection_status(uuid);if(ipg::CONNECTED==connection_status)success();elsefailed();// make sure to disconnectipg::disconnect(uuid);
1 2 3 4 5 6 7 8 91011121314
usingdotnetJmpLib;// Define the connection properties and initialize the JmpConnectionvarconnectionProperties=newConnectionProperties("10.0.0.96")// Sets the connections port to 9220.setPort(9200)// Sets the connection's login to 'jnior' for username, and 'jnior' for // password..SetCredentials("jnior","jnior")// Sets the connection to reconnect or not if the connection fails.SetReconnect(True/False);// use the connection properties that are defined to create a jmp connectionvar_jmpConnection=newJmpConnection(connectionProperties);
1 2 3 4 5 6 7 8 91011121314
importcom.integ.jmplib;// Defines a default connection properties object with IPConnectionPropertiescp=newConnectionProperties("10.0.0.96")// Sets the connections port to 9220.setPort(9220)// Sets the connection's login to 'jnior' for username, and 'jnior' for // password..setCredentials("jnior","jnior")// Sets the connection to reconnect or not if the connection fails.setReconnect(True/False);// use the connection properties that are defined to create a jmp connectionJmpConnectionjmpConnection=newJmpConnection(cp);
1 2 3 4 5 6 7 8 91011121314
importjmplib_py# Defines a default connection properties object with IPconnection_properties=jmplib_py.ConnectionProperties("10.0.0.96")# Sets the connections port to 9220.set_port(9220)# Sets the connection's login to 'jnior' for username, and 'jnior' for # password..set_credentials("jnior","jnior")# Sets the connection to reconnect or not if the connection fails.set_reconnect(True/False)# use the connection properties that are defined to create a jmp connectionjmp_connection=jmplib_py.JmpConnection(connection_properties)
Uses the previously mentioned Connection Properties. The JMP Connection Connect method is not directly callable and therefore doesn't have any returned status codes.
After creating the connection, you can wait for the connection to either connect, or timeout. The Wait For Connection function call will return the status of the connection at the time of the return.
Possible Status Returns:
INVALID_UUID: If a JMP Connection is not found for the given UUID
sequenceDiagram
autonumber
Application->>connection_monitor_object: Wait for connection
Note right of Application: Application thread blocks until the<br>connection is made/fails or the timeout expires
loop
connection_monitor_object->>connection_monitor_object: 2 second timeout
end
JmpConnection-->>connection_monitor_object: Connected / Connection Failed
Note right of Application: returns the status of the connection
connection_monitor_object->>Application: <Connection Status>
Note right of Application: Application continues...
This is how you would call it in code...
1
comingsoon...
123
// This will wait to proceed further in the code until it resolves // the status of the JMP Connection._jmpConnection.WaitForConnection();
123
// This will wait to proceed further in the code until it resolves // the status of the JMP Connection.jmpConnection.waitForConnection();
123
# This will wait to proceed further in the code until it resolves # the status of the JMP Connection.jmp_connection.wait_for_connection()
When you are done with a connection, you can us the Disconnect function to end it. To reestablish a connection to the unit, you will need to create a new connection.
Possible Status Returns:
INVALID_UUID: If a JMP Connection is not found for the given UUID
DISCONNECTED: Returned no matter what the current state of the socket is.
12
// Connection is stoppedipg::disconnect(uuid);
12
// Connection is stopped_jmpConnection.Disconnect();
12
// Connection is stopped jmpConnection.disconnect();
12
# Connection is stoppedjmp_connection.disconnect()
Optionally, a callback can be assigned that will be alerted when ever there is a change to any of the connections. In order for the collback to be effective, it must be defined before any connections are defined. To define the call back we can do the following...
1 2 3 4 5 6 7 8 9101112131415
// Define callback method. This function will get called when the status // of the connection changes.intconnection_callback(constchar*sessionId,constchar*status_description){std::cout<<std::string(sessionId)+": "+status_description<<std::endl;return0;}// Add the callback to the libraryipg::add_connection_callback(connection_callback);...// When we are done with the callback, we must remove it from the libraryipg::remove_connection_callback(connection_callback);
1 2 3 4 5 6 7 8 91011
// Defines the callback method that runs when the JMP connection's status // changes.privatestaticvoidConnectionStatusChange(stringuuid,intstatusCode,stringstatusDescription){Console.WriteLine($"{uuid}: Connection status is ({statusCode}) {statusDescription}");}// Once the ConnectionStatusChange function is defined, you can// now add the connection listener to enable the callback.// This will check for changes to the JMP connection, and run the // ConnectionStatusChange function when they occur.JmpLib.add_connection_callback(ConnectionStatusChange);
1 2 3 4 5 6 7 8 9101112
// Defines the callback method that runs when the JMP connection's status // changes.@OverridepublicvoidonConnectionStatusChange(jmpConnection,intstatusCode,StringstatusDescription){System.out.println("Connection Status Code = "+statusCode+", Connection Status Description = "+statusDescription);}// Once the OnConnectionStatusChange function is defined, you can// now add the connection listener to enable the callback.// This will check for changes to the JMP connection, and run the // onConnectionStatusChange function when they occur.JmpLib.addConnectionListener(this);
1 2 3 4 5 6 7 8 910
# Defines the callback method that runs when the JMP connection's status # changes.defon_connection_status_change(jmp_connection,statusCode:int,statusDescription:str):print(f"Authentication status code: {statusCode}. Authentication status description: {statusDescription}")# Once the on_connection_status_change function is defined, you can# now add the connection listener to enable the callback.# This will check for changes to the JMP connection, and run the # on_connection_status_change function when they occur.jmplib_py.add_connection_status_callback(on_connection_status_change)