xmppo / node-xmpp-bosh

An XMPP BOSH & WebSocket server (connection manager) written on node.js using Javascript
https://github.com/xmppo/node-xmpp-bosh
263 stars 85 forks source link

'ERROR on listener at endpoint' when changing Host #42

Closed udiudi closed 12 years ago

udiudi commented 12 years ago

I deployed my Node.js app to EC2.

On my local server, BOSH host was configured to example.dev, and now after deployment it sits on subdomain.example.com (the entire node app sits on the subdomain) and since then I get this error:

Error: ERROR on listener at endpoint: http://subdomain.example.com:5280/^\/http-bind(\/+)?$/ at Server. (/var/www/subdomain.example.com/nodechat/src/bosh.js:1874:10) at Server.emit (events.js:67:17) at Array.0 (net.js:732:14) at EventEmitter._tickCallback (node.js:192:41)

What am I doing wrong? How can I trace the issue behind this?

Thank you,

dhruvbird commented 12 years ago

Can you pull from the master branch and re-run or apply this patch ( https://github.com/dhruvbird/node-xmpp-bosh/commit/b39b1c3fd7d0b340cfa88434a426c5cc62a813b2 ) to your source and re-create this error?

This patch prints a more verbose exception.

udiudi commented 12 years ago

Applied it, and this is what I get: ERROR (Error: listen EADDRNOTAVAIL) on listener at endpoint...

thanks.

dhruvbird commented 12 years ago

This is probably because you have another daemon running on the same port or another instance of the bosh proxy on the same port. Check by running netstat -l

udiudi commented 12 years ago

I don't see it: http://d.pr/i/vHHW I even changed the port and the error from before still occurs.

dhruvbird commented 12 years ago

Maybe the fact that you have a hostname set for where to listen on is causing a problem. Try using the default of 0.0.0.0 and see if it works.

udiudi commented 12 years ago

Good, it runs, but with this configuration my client can't connect to it. I use Strophe, and it gets a Access-Control-Allow-Origin in the browser :(

So that's why I need to set a specific hostname (or maybe you have other suggestions regarding the client)

Thank you.

dhruvbird commented 12 years ago

You should not get that error since node-xmpp-bosh is configured to send the access-control headers to the browser. Check firebug (assuming firefox) for the network requests.

udiudi commented 12 years ago

No luck there too: http://d.pr/i/KF5F In options.js I see the headers array, and it has Access-Control-Allow-Origin it in, it's weird that I don't see it in the request itself.

How can I debug this? I'm pretty sure I did something wrong here (I was trying different BOSH XMPP modules with Node). All I need is to connect to Facebook's chat and send messages (preferably from the server, and not the client as I do now)

dhruvbird commented 12 years ago

Are you proxying the data via apache? If so, the first step would be to try a setup which directly connects to the bosh proxy. If that works, you know that you need to fix an apache config.

udiudi commented 12 years ago

I followed this post: http://d.pr/kCiR did curl -d "<body rid='1623252793' xmlns='http://jabber.org/protocol/httpbind' to='chat.facebook.com' xml:lang='en'ait='60' hold='1' content='text/xml; charset=utf-8' ver='1.6' xmpp:version='1.0' xmlns:xmpp='urn:xmpp:xbosh'/>" http://localhost:5280 (and 0.0.0.0:5280)

But got no response. It means there's a problem with Apache config? I added to apache2.conf the ProxyPass/Reverse

It's so strange that I'm able to run it, but don't get it with the Allow-Origin headers.

dhruvbird commented 12 years ago

I think you should first try connecting to the bosh server directly (rather than go via apache) - that will help isolate the problem.

udiudi commented 12 years ago

How can I do that?

dhruvbird commented 12 years ago

Just don't proxy your requests through apache or nginx. If you have your bosh proxy running on port 5280, make sure apache isn't listening on that port, and connect directly to it.

dhruvbird commented 12 years ago

@udiudi Any success with the direct connection approach?

udiudi commented 12 years ago

@dhruvbird sorry for the late response. I turned off Apache, ran my node app with bosh running with default configurations.

I get in the console this error: http://0.0.0.0:5280/http-bind/ Resource failed to load

dhruvbird commented 12 years ago

@udiudi don't visit http://0.0.0.0:5280/http-bind/ instead, visit http://localhost:5280/http-bind/ and see if it works.

udiudi commented 12 years ago

@dhruvbird by 'visit' do you mean from my browser? The server I have this issue with is on Amazon, localhost won't work..

Or connecting with Strophe to localhost instead 0.0.0.0:5280?

dhruvbird commented 12 years ago

@udiudi If you are hosting the server on EC2, you need to connect to the host name of the EC2 instance if you are connecting from a machine other than the machine on which you are hosting the bosh proxy.

If you are able to log in to the machine running the bosh proxy (which you should), you can run:

$> curl "http://localhost:5280/http-bind/"

That should print out a 200 OK response and show you some html. If you are not able to get that to work, then you need to debug some more to get this to work.

udiudi commented 12 years ago

@dhruvbird that's what I get in return: http://scrp.at/bBB

Let me explain the setup: I have 1 EC2 server, it has Node.js app and bosh server running (on the same machine).

dhruvbird commented 12 years ago

@udiudi That's the expected output!

So now you need to fix your apache (or reverse proxy config.) since the plain vanilla setup seems to be working fine.

udiudi commented 12 years ago

Yep. Was an Apache issue after all.

Thank you!

dhruvbird commented 12 years ago

Great! I'm glad you were able to resolve it :)