Some kind of timeout proglem with node.js / socket.io chat - node.js

We've built simple node.js socket.io chat from an example chat document. Here is our problem that we've stucked with;
When A person clicks to B person for chat it says "it's ready start conversation"
When they send message nothing happens, hitting enter only clearing message neither A nor B person sees it.
But if they do f5 both it says "it's ready to start conversation" again and now they can chat without any problem.
With this first trigger every chat can be made without f5. For example after 1-5 hours if C person clicks to D person they can start conversation without problem.
But if a day passed without any conversation people that starts first conversation on that day has to make f5 to make some kind of trigger. Then anyone after them starts without any problem.
The server goes some kind of timeout or screensaver mode..! People on first conversation always have to make f5. Then it works for a day.. I am not sending any code or something we need guidance what to look for. Node.js? socket.io? What can cause this silly problem? Thx

But if a day passed without any conversation people that starts first conversation on that day has to make f5 to make some kind of trigger. Then anyone after them starts without any problem.
This sounds like you're trying to keep a websocket connection open for several days without any client doing any reconnect?
If this is the case, then maybe it is a clientside problem. Perhaps the browser closes the websocket-connection after a long time. Your web app doesnt recognize the lack of connection and still shows "it's ready to start conversation". But browser doesnt send any messages to the server anymore.
Check this thread: howto reestablish connection
It would help a lot, if you show us some code.
Best regards

Related

How to reflect event that happened on the server, in the browser

I am a beginner with NodeJS. Now I am wondering how to signify/visualize an event that happened in the server.
For example the event might happen once in every 20sec, and I want to give a signal in the browser that the have happened.
I was thinking about the approach to request/poll the server every 10mSec, but it doesn't seem to be very efficient.
Any better ideas?
There is two way to propagate an event that happen into the server to the front.
Front polling. Every X sec the front is gonna ask the server about news.
Front : "did something happen?"
Back : "yes ..."
Websocket communication. The front open a websocket connection to the server and then wait for news. As soon as something happen on the back, the server send a message to the front. No polling, no useless messages.
A famous websocket is socket.io. What's used to create chats for example.
Schema representation of the difference of treatment :

how to get user online status with socket.io & nodeJS immediately

socket.io has a setting 'close timeout' 60s and so there is a delay about 75 seconds from user closed the webpage to trigger the event 'disconnect'(so I know he was offline).It's too long for me..what I want is a very quick response to know a user ONLINE STATUS CHANGED.I use a interval ajax get method on front-end so I know wether a user is online and if timeout he if offline , but I think it's a awful design and there must be some way better then this,will you guys help me?thx very much
Which version of socket.io do you use ?
I never see disconnect event fired after more than 1s.

Spontaneous page reload

I have a chat app built in node.js. On the first message between two clients, one of the clients will spontaneously reload. After the reload, I can reconnect to the server, and all is well - I can continue the chat.
I'm really not sure how to troubleshoot this, or what I should be looking for.
There's only one strange thing I've noted.
The user sockets are stored on the server by username. I've told the server to write *username* has connected, or *username* has disconnected The strange thing is that I get multiple logs of undefined has disconnected, and then one *username* has disconnected
Thanks for anything to point me in the right direction

NowJS takes time to fire server events with more than 5 clients connected

I'm developing a multiplayer game in NodeJS with NowJS, the thing is when more than 5
clients are connected it starts to take more time:
First I thought I was doing bad processing on server side,
so I put a console.log first line on the everyone.[event] and the
weird thing it is taking time to call it, after that everything goes
in a second.
I have downloaded the quick 10 lines chat room example here and opened 6 mozilla tabs and it happends the same, it takes time to fire the now event, not to
distribute the message or process on server-side ... any thoughts?
Thanks!
The problem was the version of NowJS & Node.js, please if you get this kind of error, try to update both to latest and put focus on what has been updated on the NowJS page.

Notifying a browser about events on server

I have a java based web application(struts 1.2). I have a requirement to display a status on the frontend (jsp). Now the status might change which my server gets notified by another server. But I want this status change to be notified to the browser.
I don't want to make a refresh at intervals. Rather I have to implement something like done in gmail chat, ie. the browser gets notified by changing events on the server.
Any ideas on how to go about this?
I was thinking on lines of opening a request to server for status, and at the server end I would hold the request and wouldn't respond back until there is a status change. Any pointers, examples on this?
Best possible solution will be to make use of XMPP protocol. It's standardized and a lot of open source solutions will get you started within minutes. You can use combination of Smack, StropheJS and Openfire to get your java based app work as desired.
There's a method called Long Polling (Comet). It basically sends a request to the server. The request thread created on the server simply waits for new data for the user, with a time limit of maybe 1 minute or more. When new data is available it is returned.
The main problem is to tackle the server-side issue, you don't want to have one thread for every user just waiting for new data. Of course you could use some asynchronous methods depending on your back-end.
Ref: http://en.wikipedia.org/wiki/Push_technology
Alternative way would be to use WebSockets. The problem is that it's not supported by all browsers today.

Resources