websocketsdocumentation
Differences
This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| websocketsdocumentation [2022/08/27 15:35] – created wikiadmin | websocketsdocumentation [2023/10/08 13:41] (current) – wikiadmin | ||
|---|---|---|---|
| Line 3: | Line 3: | ||
| ==== Overview ==== | ==== Overview ==== | ||
| - | MIStudio provides both a WebSockets | + | MIStudio provides both a WebSocket |
| + | |||
| + | ==== Example: Running Without Security ==== | ||
| + | |||
| + | WebSockets can run without security using a socket URL which is of the format <code html> ws:// | ||
| + | |||
| + | Start a new project in MIStudio and add a SwingTextField and an Annuniciator. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The SwingTextField will be used to send a String value to the Server, and the Annunciator will be used to show this value using the Client which has a connection to the Server. | ||
| + | |||
| + | Copy these graphics to the MIStudio Diagram window. Add a WebSocketClient bean and a WebSocketServer bean to the diagram window. Connect the SwingTextField to the Input of the WebSocketSever. Connect the Output of the WebSocketClient to the Annunciator input. | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The only configuration needed for the no-security test is to type the URL of the WebSocket Server into the WebSocket Client' | ||
| + | |||
| + | {{: | ||
| + | |||
| + | To test this insecure connection, put MIStudio into LIVE mode and use the MIStudio Test Frame to enter a value into the text field. It will appear in the client' | ||
| + | |||
| + | The steps to use the WebSocket server and client with a secure connection is described in the next sections, starting with making a certificate for the server. | ||
| ==== Self-Signed Certificate Generation ==== | ==== Self-Signed Certificate Generation ==== | ||
| Line 9: | Line 31: | ||
| 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 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: | + | <note important> |
| - | //openssl req -newkey rsa:2048 -x509 -keyout key.pem -out cert.pem -days 365// | + | OpenSSL is usually installed by default on Linux systems. For Windows you can get OpenSSL 1.1.1q from https://slproweb.com/products/Win32OpenSSL.html |
| - | The tool will prompt us to enter a PEM passphrase | + | To generate the private (key.pem) |
| - | + | ||
| - | When prompted for the " | + | |
| - | URI wss:// | + | |
| - | //Common Name (e.g. server FQDN or YOUR name) []: | + | <code Windows> |
| + | openssl req -newkey rsa:2048 -x509 -keyout key.pem -out cert.pem -days 365 | ||
| + | </code> | ||
| + | |||
| + | OpenSSL will prompt you for several values. You can enter a dot (" | ||
| + | |||
| + | Passphrase: he tool will prompt us to enter a PEM passphrase and other information. | ||
| + | To generate a private key without encrypting | ||
| + | |||
| + | <code Windows> | ||
| + | openssl req -newkey rsa:2048 -nodes -x509 -keyout key.pem -out cert.pem -days 365 | ||
| + | </code> | ||
| + | |||
| + | Common Name: When prompted for the " | ||
| + | |||
| + | <code Windows> | ||
| + | Common Name (e.g. server FQDN or YOUR name) []: | ||
| + | </code> | ||
| Once we've answered all the prompts, the openssl tool outputs two files: | Once we've answered all the prompts, the openssl tool outputs two files: | ||
| Line 28: | Line 64: | ||
| Some additional details are provided at: | Some additional details are provided at: | ||
| - | The server requires that the certificate be in | + | The server requires that the certificate be in PKCS12 format. So we need to convert the cert.pem generated in the step above to cert.p12 (a certificate in PKCS12 format). |
| + | To convert the server certificate PEM into a PKCS12 format, and assigning " | ||
| - | ==== Properties ==== | + | <code Windows> |
| - | === Web Socke === | + | openssl pkcs12 -export -in cert.pem -inkey key.pem -out cert.p12 -passout pass: |
| + | </ | ||
| + | |||
| + | While the command runs, you'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). The command line above assigns the password " | ||
| + | |||
| + | After that, you'll have a cert.p12 KeyStore stored in PCKS12 format. | ||
| + | |||
| + | Copy cert.p12 and cert.pem into the UserFiles folder of the MIStudio project. | ||
| + | |||
| + | Set the " | ||
| + | |||
| + | |||
| + | |||
| + | ==== Server | ||
| + | |||
| + | WS Port: | ||
| + | |||
| + | Certificate file name: | ||
| + | |||
| + | Certificate Password: | ||
| + | |||
| + | ==== Client Properties | ||
| + | |||
| + | Server URI: | ||
| + | |||
| + | <wrap hi>Be sure to use wss:%%//%% for a secure connection (with certificates) and ws:%%//%% for an insecure (no certificates) connection</ | ||
| + | |||
| + | Trusted Certificate: | ||
| ==== Examples of Use ==== | ==== Examples of Use ==== | ||
| - | ==== Notes ==== | + | As simple usage of WebSockets in MIStudio might look like this: |
| + | |||
| + | {{: | ||
| + | |||
| + | Values typed into the TextField, connected to the server, will be seen in the Annunciator, | ||
| + | |||
| + | The server configuration is: | ||
| + | |||
| + | {{: | ||
| + | |||
| + | The client configuration is: | ||
| + | |||
| + | {{: | ||
| - | see also: [[Rolling Array Builder Documentation|Rolling Array Builder]] | ||
websocketsdocumentation.1661628953.txt.gz · Last modified: by wikiadmin
