User Tools

Site Tools


websocketsdocumentation

This is an old revision of the document!


Web Sockets Client and Server

Overview

MIStudio provides both a WebSockets Server and a WebSockets Client. Boththe WebSocketsServer and Client can run without security, or with a known CA (the default) or with self-signed certificates.

Self-Signed Certificate Generation

To run the server with self-signed certificates you need to generate a public and private certificate for the server and the public certificate must be moved to the client.

To generate server certificates run:

openssl req -newkey rsa:2048 -x509 -keyout key.pem -out cert.pem -days 365

The tool will prompt us to enter a PEM passphrase and other information. You can choose a passphrase, but need to save it for use below.

When prompted for the “Common Name” add the name of the server. eg for the default URI wss://'localhost:8887 add:

Common Name (e.g. server FQDN or YOUR name) []:localhost

Once we've answered all the prompts, the openssl tool outputs two files:

  • key.pem (the private key)
  • cert.pem (a public certificate)

We'll use these files to generate our self-signed certificate.

Some additional details are provided at:Converting a PEM File to Java KeyStore Format which was the source of this information.

The server requires that the certificate be in PKCS12 format: To convert PEM into a PKCS12 format:

openssl pkcs12 -export -in cert.pem -inkey key.pem -out certificate.p12 -name “certificate”

While the command runs, we'll be prompted to enter the passphrase that we created previously for key.pem: Enter pass phrase for key.pem: [This is the passphrase you entered above] And then we'll see the prompt asking for a new password for certificate.p12: Enter Export Password: [This can be the same as the passphrase or different. This is used in the server “CertPassword” property.

After that, we'll have a certificate.p12 KeyStore stored in PCKS12 format. Copy certificate.p12 and cert.pem into the UserFiles folder of the MIStudio project.

Set the “P12Certificate” property to be “certificate.p12” and the Cert Password to be the password entered above. Set the “TrustedCert” property in the client to be “cert.pem” (or copy the certificate to a different web socket client following the instructions for that client).

Server Properties

WS Port:(Port)This will be the port in the URL, eg ws://'yourhost:port

Certificate file name:(P12Certificate)The name of the file containing the PKCS12 formatted certificate

Certificate Password:(CertPassword)The password of the certificate

Client Properties

Server URI:(ServerUri)This URI of the server, eg wss://'yourhost:port

Trusted Certificate:(TrustedCert)The trusted server certificate in PEM format

Examples of Use

As simple usage of WebSockets in MIStudio might look like this:

Websocket Configuration

Values typed into the TextField, connected to the server, will be seen in the Annunciator, connected to the Client.

The server configuration is:

Server Configuration

The client configuration is:

Client Configuration

websocketsdocumentation.1661630241.txt.gz · Last modified: by wikiadmin

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki