Skip to main content

Updating AMPS Client Connections

Client Connection Strings

Use the URI that matches the proxy and AMPS transport configuration:

  • Secure TCP connections: tcps://localhost:443/tcps/amps/json?http_preflight=true
  • Secure WebSocket connections: wss://localhost:443/wss/amps/json
  • Standard non-SSL TCP connections: tcp://localhost:80/tcp/amps/json?http_preflight=true
  • Standard non-SSL WebSocket connections: ws://localhost:80/ws/amps/json

The code examples below all use the secure URLs.

For a non-SSL deployment, replace tcps with tcp, wss with ws, port 443 with 80, and the /tcps/ and /wss/ paths with /tcp/ and /ws/.

WebSocket connections don't require the HTTP Preflight option as they use an HTTP Upgrade mechanism to upgrade to the WebSocket protocol by default.

For more information on HTTP Preflight, see HTTP Preflight in the AMPS User Guide.

Example Client Connections

For install and usage details, see Obtaining and Installing the AMPS Client.

const { Client } = require('amps')

// required when the CA certificates are self-signed
process.env.NODE_TLS_REJECT_UNAUTHORIZED = 0;

async function main() {
// Connect and logon
const client = new Client('javascript-proxy-client')
// HTTP preflight is not required for standard websocket connections
await client.connect('wss://localhost:443/wss/amps/json')
console.log('connected!')

// No difference in usage once the client is connected
client.publish("test", "{\"hello\":\"world\"}")
client.disconnect()
}

main()

This example creates an AMPS Client and establishes a secure WebSocket connection to AMPS through the Apache reverse proxy.

tip

If the clients fail to connect after following the above steps on Fedora/Red Hat, try running the following command:

sudo setsebool -P httpd_can_network_connect 1

This command modifies a security setting in SELinux (Security-Enhanced Linux) to allow the httpd (web server) process to make network connections. It also ensures that this setting persists across system reboots.

If you use the Fedora localhost certificate shown in this guide, connect to localhost rather than 127.0.0.1, or replace the certificate with one that matches the hostname clients will use.