0

I have a setup with node and socket io to send a dymanic time (HH:MM:SS) to my index.php file that is served by apache. So far im able to see the time properly running on the php file.

Now what im trying to achive is to search dynamicly inside a text file for the text just after a time marker (that would be the time received through socket io) and print it, by example: Time received: 00:05:00, my text file look like:

<00:00:00> Helo World

<00:05:00> Welcome to my presentation

<00:10:00> Now is time for a coffe

So when the time received is 00:10:00 i can display the text that follow. I will really appreciate any advice about the best approach to do this.

Regards

Aramil
  • 411
  • 1
  • 5
  • 17

1 Answers1

0

If you're trying to do a search through a text file, if I understand the problem correctly, you should be doing it on the server, not on the client.

It sounds like you should do the timestamp and file processing on the server, and send the content to the client after.

So your flow would be something like this: 1) Get timestamp on server 2) Find text from file (using fs module) 3) Send text to client via socket.io

To search through a file you can use the file system module that is a part of NodeJS's core.

Let me know if this helps

zahid
  • 83
  • 1
  • 8
  • Hey! zmhr, you are right, that should be the flow. thanks for the advice, im reading the your link, its fs.read right? Im googling it atm for a example to filter the result by a search tag, that in my case would be the timestamp. Thanks! – Aramil Feb 25 '14 at 17:44
  • Hey zmhr this is what i have so far, but no clue how to add the timestamp condition on the readfile: require("fs").readFile('test.txt', 'utf-8', function (err, contenido) { if (err) throw err; console.log(contenido) function sendSubs() { io.sockets.emit('subs', { subs: contenido }); } setInterval(sendSubs, 1000); }); – Aramil Feb 25 '14 at 20:37
  • What is the exact thing you're trying to do? Be a little more specific and I can help some more. – zahid Feb 26 '14 at 05:18
  • Thanks zmhr i followed your advice and finally made it with the help of all of you guys. Here is the link of the [http://stackoverflow.com/questions/22027776/node-js-xml2js-result-from-attribute](http://stackoverflow.com/questions/22027776/node-js-xml2js-result-from-attribute) – Aramil Feb 26 '14 at 06:42