Skip to main content

Connection Parameters for AMPS

When specifying a URI for connection to an AMPS server, you may specify a number of transport-specific options in the parameters section of the URI connection parameters. Here is an example:

tcp://localhost:9007/amps/json?tcp_nodelay=true&tcp_sndbuf=100000

In this example, we have specified the AMPS instance on localhost, port 9007, connecting to a transport that uses the amps protocol and sending JSON messages. We have also set two parameters: tcp_nodelay, a Boolean (true/false) parameter, and tcp_sndbuf, an integer parameter. Multiple parameters may be combined to finely tune settings available on the transport. Normally, you'll want to stick with the defaults on your platform, but there may be some cases where experimentation and fine-tuning will yield higher or more efficient performance.

The AMPS client supports the value of tcp in the scheme component connection string for TCP/IP connections, and the value of tcps as the scheme for SSL encrypted connections.

IPv6 Connections

Starting with version 5.3.3.0, the AMPS client supports creating connections over both IPv4 and IPv6 protocols if supported by the underlying Operating System.

By default, the AMPS client will prefer to resolve host names to IPv4 addresses, but this behavior can be adjusted by supplying the ip_protocol_prefer transport option, described in the table below.

TCP and SSL Transport Options

The following transport options are available for TCP connections:

OptionDescription
bind

(IP address) Sets the interface to bind the outgoing socket to.

Starting with version 5.3.3.0, both IPv4 and IPv6 addresses are fully supported for use with this parameter.

tcp_rcvbuf(integer) Sets the socket receive buffer size. This defaults to the system default size. (On Linux, you can find the system default size in /proc/sys/net/core/rmem_default.)
tcp_sndbuf(integer) Sets the socket send buffer size. This defaults to the system default size. (On Linux, you can find the system default size in /proc/sys/net/core/wmem_default.)
tcp_nodelay(boolean) Enables or disables the TCP_NODELAY setting on the socket. By default TCP_NODELAY is disabled.
tcp_linger(integer) Enables and sets the SO_LINGER value for the socket By default, SO_LINGER is enabled with a value of 10, which specifies that the socket will linger for 10 seconds.
tcp_keepalive(boolean) Enables or disables the SO_KEEPALIVE value for the socket. The default value for this option is true.
ip_protocol_prefer(string) Influence the IP protocol to prefer during DNS resolution of the host. If a DNS entry of the preferred protocol can not be found, the other non-preferred protocol will then be tried.

If this parameter is not set, the default will be to prefer IPv4.

If an explicit IPv4 address or IPv6 IP address is provided as the host, the format of the IP address is used to determine the IP protocol used and this setting has no effect.

Supported Values:

ipv4: Prefer an IPv4 address when resolving the host

ipv6: Prefer an IPv6 address when resolving the host

This parameter is available starting with version 5.3.3.0.

Using HTTP Preflight for Connection Upgrades

Some users need to minimize the number of externally accessible ports while still allowing multiple AMPS transports to be used in environments with strict firewall policies for security reasons.

To address this, AMPS supports an HTTP Preflight mechanism that enables TCP clients to share the same external port used for WebSockets. Instead of requiring a dedicated external TCP port, clients can establish a connection over an existing HTTP endpoint. This reduces the number of open network ports while maintaining full TCP/TCPS functionality.

This feature works by leveraging HTTP Upgrade requests, similar to WebSockets, allowing clients to connect via an initial HTTP request before transitioning to a full TCP/TCPS session. Additionally, the HTTP preflight mechanism enables custom HTTP headers to be included in the initial handshake, making it easier to integrate with reverse proxies.

To request HTTP preflight, add the http_preflight=true option to the connection string. For example:

tcp://proxy-to-amps.example.com:8020/client/amps/json?http_preflight=true

To learn more about HTTP Preflight, including how to enable it and configure an NGINX proxy, refer to the HTTP Prefligh t section in the AMPS User Guide and the HTTP Preflight- Proxy Play: AMP S Unlocked blog.

Compress Network Traffic

By default, network traffic to the AMPS server is not compressed.

The AMPS Java client optionally supports compressing traffic between the application and AMPS. To enable this, add the compression option to the connection string. In this release, the AMPS Java client supports zlib compression to the server.

Notice that compressing and decompressing data performs additional work on both the client and server side to compress and decompress the data. The goal is reducing the bandwidth required for the traffic. If bandwidth is at a premium and the data compresses well, this can produce gains in overall performance. In other situations, the benefit can be negligible or create extra latency.

60East recommends testing with your message data and volumes to determine the effect of compression for your usage.

For example:

tcp://amps.example.com:9007/amps/json?compression=zlib

AMPS Additional Logon Options

The connection string can also be used to pass logon parameters to AMPS. AMPS supports the following additional logon option:

OptionDescription
prettyProvide formatted representations of binary messages rather than the original message contents.