xmppjs / xmpp.js

XMPP for JavaScript
ISC License
2.19k stars 372 forks source link

ENOTFOUND: XMPP.start(0 #824

Closed destinyb-realityi closed 4 years ago

destinyb-realityi commented 4 years ago

I'm trying to connect to my XMPP server but I'm getting an error:

Error: getaddrinfo ENOTFOUND example.net:8086
    at GetAddrInfoReqWrap.onlookupall [as oncomplete]

I'm using the following code to attempt to connect:

const { client, xml, jid } = require('@xmpp/client')

xmpp = client({
    service: 'example.net:8086',
    resource: 'myResource,
    username: 'myUsername@example.net',
    password: 'myPassword'
})

debug(xmpp, true)

xmpp.on('error', err => {
    alert(err)
})

xmpp.on('offline', () => alert('offline'))

xmpp.on('online', address => {
    alert(`You're connected!`)
})

xmpp.start().catch(console.error)
destinyb-realityi commented 4 years ago

I couldn't find any other way to connect using my domain name. I tried using xmpp://example.net:8086 as the service: but I kept getting the error Error: connect ECONNREFUSED 127.0.0.1:5222

sonnyp commented 4 years ago

Did you forget the : ? xmpp://, not xmpp//

destinyb-realityi commented 4 years ago

Did you forget the : ? xmpp://, not xmpp//

I did not. Sorry, I forgot to add it to my example. I tried with : and without it and had almost the same result.

I can connect easily, however, using simple-xmpp but I wanted to use @xmpp/client since this is more recently updated and maintained.

sonnyp commented 4 years ago

are you trying to use websocket or tcp?

is it a public server? if so you can send me an email (it's in my GitHub profile) with where you are trying to connect exactly and I can debug.

destinyb-realityi commented 4 years ago

are you trying to use websocket or tcp?

is it a public server? if so you can send me an email (it's in my GitHub profile) with where you are trying to connect exactly and I can debug.

I was trying TCP. I think the server is too old for it to have websockets but I could be wrong. The server is also a private server.

sonnyp commented 4 years ago

what error do you get exactly with service: "xmpp://domain:5222" ? what about service: "domain" ?

destinyb-realityi commented 4 years ago

When using service: "domain" I get the error net::ERR_NAME_NOT_RESOLVED When using service: 'xmpp://domain:5222' I get Error: connect ECONNREFUSED 127.0.0.1:5222

Example code when trying xmpp://domain:5222

const { client, xml, jid } = require('@xmpp/client')

let xmpp1 = client({
    service: 'xmpp://domain:5222',
    domain: 'example.net:8086',
    resource: 'myResource',
    username: 'username',
    password: 'password'
})

xmpp1.on('error', err => alert(err))
xmpp1.on('offline', () => alert ('Offline'))
xmpp1.on('online', addr => alert(addr))

xmpp1.start().catch(alert)

Example code when using service: "domain":

const { client, xml, jid } = require('@xmpp/client')

let xmpp1 = client({
    service: 'domain',
    domain: 'example.net:8086',
    resource: 'myResource',
    username: 'username',
    password: 'password'
})

xmpp1.on('error', err => alert(err))
xmpp1.on('offline', () => alert ('Offline'))
xmpp1.on('online', addr => alert(addr))

xmpp1.start().catch(alert)
sonnyp commented 4 years ago

does not look like an error with xmpp.js

in the first case your computer could't resolve the domain

in the second case it is resolving the domain to 127.0.0.1 (localhost) which is why it fails to connect

please verify you're entering the correct domain

destinyb-realityi commented 4 years ago

It’s definitely the correct domain. Like I said, it’s working perfectly fine with simple-xmpp and node-xmpp but not with @xmpp/client. It also doesn’t make sense that it would resolve the domain to localhost when the domain i’m entering in isn’t even hosted on my computer.

destinyb-realityi commented 4 years ago

Here's how I'm connecting to it using simple-xmpp:

xmpp.connect({
    port: 8086,
    jid: 'username',
    password: 'password',
    host: 'example.net',
})

This code works 100% on the same computer that @xmpp/client is failing to work on.

sonnyp commented 4 years ago

@destinyb-realityi you're mixing up domain and service

service is the endpoint (hostname, port, ...) to connect to (the computer), domain is the XMPP domain

If your domain is "unicorn.net" and is hosted on "rainbow.net" and listening on port 8086 you should use:

    service: 'xmpp://rainbow.net:8086',
    domain: 'unicorn.net'

See https://github.com/xmppjs/xmpp.js/tree/master/packages/client#client-1

destinyb-realityi commented 4 years ago

How I understand it is that if the domain is separate from the hostname, then you'd use your example above. If they're identical, then you'd only use service: 'xmpp://example.net:8086 right?

What could be causing @xmpp/client to resolve xmpp://example.net:8086 to be 127.0.0.1:5222? That's what I'm still confused about when it works with the depreciated node-xmpp-client.

I'm trying to the below but it's still resolving to 127.0.0.1:5222

const { client, xml, jid } = require('@xmpp/client')

let xmpp1 = client({
    service: 'xmpp://exmaple.net:8086',
    resource: 'myResource',
    username: 'username',
    password: 'password'
})

xmpp1.on('error', err => alert(err))
xmpp1.on('offline', () => alert ('Offline'))
xmpp1.on('online', addr => alert(addr))

xmpp1.start().catch(alert)

Why would it change the port it's looking on along with the hostname?

destinyb-realityi commented 4 years ago

I just attempted to ping the XMPP hostname I'm using, with the port number, via terminal and got Unknown host. I was able to resolve the IP address when I pinged the hostname without the port though.

So then I attempted to connect the client without the port number but got the error Error: connect ECONNREFUSED 127.0.0.1:5222

const { client, xml, jid } = require('@xmpp/client')

let xmpp1 = client({
    service: 'xmpp://example.net',
    resource: 'myResource',
    username: 'username',
    password: 'password'
})

xmpp1.on('error', err => alert(err))
xmpp1.on('offline', () => alert ('Offline'))
xmpp1.on('online', addr => alert(addr))

xmpp1.start().catch(alert)
destinyb-realityi commented 4 years ago

Trying to use the direct IP address and port in the service field is returning with this error: GET https://0.000.000.000:8086/.well-known/host-meta net::ERR_SSL_PROTOCOL_ERROR

const { client, xml, jid } = require('@xmpp/client')

let xmpp1 = client({
    service: '0.000.000.000:8086',
    resource: 'myResource',
    username: 'username',
    password: 'password'
})

xmpp1.on('error', err => alert(err))
xmpp1.on('offline', () => alert ('Offline'))
xmpp1.on('online', addr => alert(addr))

xmpp1.start().catch(alert)
destinyb-realityi commented 4 years ago

Sorry to keep commenting without a response, just trying to move this along. I did a bit more digging and looked into the error thrown above. It appears in the @xmpp/resolve/lib/http.js file it's executing this code return fetch(https://${domain}/.well-known/host-meta) but it's failing to find the file .well-known/host-meta on my server. I did a quick scan on the server and found that to be accurate. The ejabberd server I'm trying to connect to is extremely outdated, 2014 or later, so that could make sense why that file isn't there.

I guess the question now is, is there a plan to support older ejabberd servers? Is there a work around to not having this file? Is there any documentation still remaining for node-xmpp since that does connect? I haven't been able to find much since it's deprecation.

sonnyp commented 4 years ago

the fetch of .well-known/host-meta is only a try and there should be no consequence if it's not available. Also it's not related to ejabberd. (https://xmpp.org/extensions/xep-0156.html)

Are you using Node.js or the browser?

If you're using the browser then you're not trying to connect via TCP and you need WebSocket support on your XMPP server (still doesn't explain why it resolves to 127.0.0.1 though) (xmpp.js does not support http/bosh)

If you're using Node.js try the following:

const resolve = require('@xmpp/resolve')
resolve('example.net').then(console.log).catch(console.error)

and also

const {client} = require('@xmpp/client')
const debug = require('@xmpp/debug')

const xmpp = client({
  service: 'xmpp://example.net:8086',
  resource: 'myResource',
  username: 'username',
  password: 'password',
})

debug(xmpp, true)

xmpp.start()
destinyb-realityi commented 4 years ago

When trying resolve(...) I got the below error:

Uncaught TypeError: Cannot read property 'connect' of undefined
    at module.exports (/Users/.../node_modules/@xmpp/resolve/index.js:64)
    at xmpp-2.js:2

When trying the second test I got the following:

rror: connect ECONNREFUSED 127.0.0.1:5222
    at TCPConnectWrap.afterConnect [as oncomplete]

Uncaught (in promise) Error: connect ECONNREFUSED 127.0.0.1:5222
    at TCPConnectWrap.afterConnect [as oncomplete]

Error: connect ECONNREFUSED 127.0.0.1:5222
    at TCPConnectWrap.afterConnect [as oncomplete]

I also got the above errors when I tried using the direct IP address rather than the hostname. If it helps, I'm using the following versions of @xmpp/*:

"@xmpp/client": "^0.11.1",
"@xmpp/debug": "^0.11.0",
"@xmpp/resolve": "^0.11.0",
sonnyp commented 4 years ago

For the first one, sorry I meant:

const resolve = require('@xmpp/resolve/resolve')
resolve('example.net').then(console.log).catch(console.error)
sonnyp commented 4 years ago

What if you ping the domain? Without port number. Do you get the right ip address?

ping example.net
destinyb-realityi commented 4 years ago

I updated it to use require('@xmpp/resolve/resolve') and got the below response: I removed the actual IP addresses for security reasons.

[
    {
        "family": 4,
        "address": "00.000.000.000",
        "uri": "xmpps://00.000.000.000:5223"
    },
    {
        "family": 4,
        "address": "00.000.000.000",
        "uri": "xmpp://00.000.000.000:5222"
    }
]

Running ping also returns the same IP address as what's listed above. I did attempt to add the port when I ran resolve(...) but that failed with: I sort of expected that since when I tried to ping the IP address with the port it failed.

Error: getaddrinfo ENOTFOUND example.net:8086
    at GetAddrInfoReqWrap.onlookupall [as oncomplete]

I did also just try to remove the port 8086 from my connection with node-xmpp-client and that worked as well, so I guess 8086 was unnecessary. However, I still can't get a connection with @xmpp/client even without the port.

sonnyp commented 4 years ago

I sort of expected that since when I tried to ping the IP address with the port it failed.

You can't use ping with a port. If you want to test if a port is open use something else https://devconnected.com/how-to-ping-specific-port-number/

Please find out what is the correct hostname and port.

vichiodo commented 4 years ago

Hello, I'm having the same problem but when I run directly from my project it connects but when using in my Electron application gives this error: Error: connect ECONNREFUSED 127.0.0.1:5222 at TCPConnectWrap.afterConnect [as oncomplete]

Did someone find a solution? @destinyb-realityi did you work this out??

sonnyp commented 4 years ago

Closing due to lack of activity, if someone else encounters this issue please feel free to comment with as many details as possible.