Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to keep connection open? #54

Closed
goloroden opened this issue Dec 28, 2014 · 5 comments
Closed

How to keep connection open? #54

goloroden opened this issue Dec 28, 2014 · 5 comments

Comments

@goloroden
Copy link

Supposed I send some JSON data to the client using Oboe.js that is created dynamically by the server. From time to time, creation of this data takes some time, so after 120 seconds of inactivity, the connection is closed.

How can I force the connection to stay open infinitely?

The most obvious approach is using a timer and sending some fake data, but this means that my client app has to filter out the fake data.

Is there a better approach?

@ooxi
Copy link
Contributor

ooxi commented Jan 2, 2015

The question is why does your server drop the connection after 120 seconds of inactivity? Browsers do not normally act this way if you start sending at least some data (for example the { if you intend to send an object).

@jimhigson
Copy link
Owner

Yeah, like @ooxi says, I'm not seeing why the server would shut the connection if not data is being sent down it.

If the server is closing the connection, because Oboe is a client-side library so there's not much it can do to influence the behaviour on the server.

The only client side answer I can think of is to have the client re-open the connection when it goes down. You'd probably lose messages sent in the meantime though.

If you want to filter out fake data, you could always tag 'real' data with an attribute and then detect it like: oboe(url).node('!.{notfake}', function(realData){})

@JuanCaicedo
Copy link
Collaborator

@goloroden What languages/frameworks are you using on your server-side? I would encourage you to ask the question there since as @jimhigson mentioned, this is out of Oboe's control. Would love to help though!

@goloroden
Copy link
Author

We are using Node.js on the server.

@JuanCaicedo
Copy link
Collaborator

@goloroden I think you might be able to achieve this using the keep-alive http header. You could pass it with oboe like this

oboe({
    url: 'http://localhost:3000/data',
    headers: {
      'Connection' : 'keep-alive'
    }
  })

You need to teach your node server how to handle that header though since it seems like there's no official spec for it. I haven't tried it, but you could try using the agentkeepalive module.

Hopefully that works, I would be interested to find out how it goes!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants