igrigorik / em-websocket

EventMachine based WebSocket server

Home Page:http://www.igvita.com/2009/12/22/ruby-websockets-tcp-for-the-browser/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Server response is not returned simultaneously as the file it is reading is updated but it is just returned just once when last send returns

Suryansh-Bhadouria-007 opened this issue · comments

ws.onmessage do |msg|
puts "Received Message: #{msg}"
db=Daybreak::DB.new "example.db"
puts "read keys for 1st time"
keys=db.keys
msg=returnKeys(db,keys)
puts "sent msg"
ws.send msg
puts"SLEEP 1 BEGINS"
sleep 2
puts"SLEEP 1 ENDS"
db1=Daybreak::DB.new "example.db"
puts "read keys for 2nd time"
keys_new=db1.keys
msg_new=returnKeys(db1,keys_new)
puts"#{msg}"
puts"_______________________________________________________"
puts"#{msg_new}"
while (!msg.eql?msg_new) do
puts "WHILE BEGINS"
puts "sent msg_new"
ws.send msg_new
db=Daybreak::DB.new "example.db"
keys=db.keys
msg=returnKeys(db,keys)

      puts "sleep inside while begins"
      sleep 2
      puts "sleep inside while ends"
      db1=Daybreak::DB.new "example.db"
      keys_new=db1.keys
      msg_new=returnKeys(db1,keys_new)


  end   
  puts "WHILE ENDS" 
  db.close


  end

I suggest reading up on eventmachine - things will then make much more sense - allow me to be biased and point you towards my introduction ;) http://rubylearning.com/blog/2010/10/01/an-introduction-to-eventmachine-and-how-to-avoid-callback-spaghetti/

i want to read a file that is being updated and send tyhe response to the client .Now I am able to send the response and am able to see that the content of the updated file is returned every time it is sent by the server but it is not visible simultaneously as it is returned(i am hoping it is),rather it is visible as a single updated file when the server sends its last response.The server's on message function is as shown above and it is invoked by the client which sends a message on clicking a button .plz help.
ps. i have read your blg and its helpful but i am not able to solve this issue .kindly help.

I'm very sorry, but I don't have time to implement this for you - I'm sure you can work it out.

Thank you for the kind response