Host discovery

XMPP has various mechanisms build to automatically discover the connection properties for your server.

When the Socket Transport is used then XMPP requires SRV records. SRV DNS records are used to locate the hostname and port of the XMPP service automatically. When the Socket Transport is used then SRV resolving is used by default.

For the WebSocket Transport XEP-0156 Discovering Alternative XMPP Connection Methods is enabled and used by default to locate the URIs of the websocket uri.

If you don’t want to use SRV records you can also specify the hostname and port manual. This is often useful in development for testing purposes. There are servers which do not use SRV records, and where the server hostname does not match the XMPP domain. In those cases the hostname must be set manual by the application. This where we can use a StaticNameResolver instead.

Example: setting host and port manual for socket transport

var xmppClient = new XmppClient(
    conf =>
    {
        conf.UseSocketTransport(new StaticNameResolver(new Uri("tcp://localhost:5222")));
    })
{
    Jid = "user@server.com",
    Password = "secret"
};    

Example: setting websocket uri manual

var xmppClient = new XmppClient(
    conf =>
    {
        conf.UseWebSocketTransport(new StaticNameResolver(new Uri("wss://example.com")));
    })
{
    Jid = "user@server.com",
    Password = "secret"
};