MexBIOS Development Studio: Client Server technology

CLIENT SERVER TECHNOLOGY

 

In MexBIOS™ Development Studio an interprocessor communication feature with client-server architecture is built in.

A server outputs necessary data on client’s request.

The client initiates connection to the server and sends a request for outputting the necessary data.

While starting the MexBIOS™ Development Studio the server is initiated automatically. The server while initiating reserves the TCP/IP protocol port. Default port number is 654321. Several applications can not exploit the same port at the same time, therefore, if while starting the MexBIOS™ Development Studio the port is already occupied by another running copy of MexBIOS™ Development Studio or by any other software exploiting the TCP/IP protocol, an error message is output.

The port number can be changed in Server inlay under Server Upper panel.

Fig. 1. Port number setting
Start/Stop server button starts and stops the server.
Fig. 2. Start/Stop server button
 
If an error message about the port ocupancy is displayed, you have to change its number to any other free one, following which you can start the server again.
To label the data, which must be output by TCP/IP protocol, one should:
  1. Add to the Workspace an OUT block. 
  2. Assign to the block a visual control Server.
  3. Set the visual control parameters.
Fig. 3. Assigning the visual control Control Server
 
To assign the visual control in Inspector only Data Address field is displayed.
 
Fig. 4. Server setting
 
The number in the field indicates the data address, in which it can be requested from server. To input the data by TCP/IP protocol you must:
  1. Add an IN block to the Workspace. 
  2. Assign a visual control Client for the block.
  3. Set the visual control parameters.
Fig. 5. Assigning the visual control Control Client
 
To assign the visual control Control Client in Inspector three fields are displayed:
  1. Server Address – computer name in network or IP address, in which a server is running, to which a client is connecting.
  2. Port, in which the server is running.
  3. Address of the data requested from the server.
Fig. 6. Client settings
 
 
LINKING-UP WITH EXTERNAL SOFTWARE

 

For communication with external applications in MexBIOS™ Development Studio an interprocessor communication feature is built-in. The feature is based on the socket software interface, and application-specific protocol of data exchange. An external application can be a server one for MexBIOS™ Development Studio, i.e. it can provide data for processing in the environment. Also an external application can be a client one, i.e. it can receive data from MexBIOS™ Development Studio for further processing. As a default the MexBIOS™ Development Studio utilizes a receiving socket, bound to port number 654321, however, if this port is already occupied by another application, MexBIOS™ Development Studio can exploit any other port.

Data exchange between client and server is carried out strictly by application-specific protocol. The protocol essence is shown in fig. 7.

 

Fig. 7. Data exchange between client and server

 

After successful connection the client can send requests to server and receive responses from server.

Client request for data outputting is an integer number (32 bits), which value is data address requested from server. Each variable in server has its own address, by which its current value can be requested. The variable address is set in appropriate visual control.

Server response is two numbers. The first number (32 bits) is a validator that indicates validity of the received data. If validator is «0», then the data are valid, if it is «1» – the data address is incorrect (there is no data in this address), if it is «2» – server is not running. The second number (64 bits) is the variable value in floating-point format from the address, sent to server in the request.

An example of requesting and the response processing are shown below.

 

 

enum TValidators{
    vOK                                  = 0,
     vINVALID_INDEX                 = 1,
     vSERVER_IS_NOT_UPDATING = 2,
};
typedef struct {
   int    Validator;
   double Data;
}
TResp;
 
//-----
int        Addr = 0;
TResp      Resp;
double     SignalValue = 0;
 
send(SockClient,(char*)&Addr,  sizeof(int),     0 );
recv(SockClient,(char*)&Resp,  sizeof(TResp), 0 );
 
if(Resp.Validator == vOK)
SignalValue = Resp.Data;

 

 

 

 

 

 

 

 

 

 

Теги: 
ClientServer