websocketsdocumentation
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| websocketsdocumentation [2022/08/27 15:57] – 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 PKCS12 format: | + | The server requires that the certificate be in PKCS12 format. So we need to convert |
| - | To convert | + | |
| - | openssl pkcs12 -export -in cert.pem -inkey key.pem -out certificate.p12 -name "certificate" | + | To convert the server |
| - | While the command runs, we'll be prompted to enter the passphrase that we created previously for key.pem: | + | <code Windows> |
| - | Enter pass phrase for key.pem: [This is the passphrase you entered above] | + | openssl pkcs12 -export -in cert.pem -inkey |
| - | And then we'll see the prompt asking for a new password for certificate.p12: | + | </ |
| - | Enter Export Password: | + | |
| - | After that, we' | + | While the command runs, you' |
| - | Set the " | + | 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 " | ||
| Line 46: | Line 84: | ||
| ==== Server Properties ==== | ==== Server Properties ==== | ||
| - | WS Port: | + | WS Port: |
| Certificate file name: | Certificate file name: | ||
| Line 54: | Line 92: | ||
| ==== Client Properties ==== | ==== Client Properties ==== | ||
| - | Server URI: | + | 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: | + | Trusted Certificate: |
| ==== Examples of Use ==== | ==== Examples of Use ==== | ||
websocketsdocumentation.1661630241.txt.gz · Last modified: by wikiadmin
