Announcement

Collapse
No announcement yet.

Streaming Data: Reading a file currently being written or other method help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Streaming Data: Reading a file currently being written or other method help

    I am trying to read data coming from a TCP stream and then delimit the data and distribute it accordingly. The current method I am using is On Timer run netcat and command. While its doing a ridiculous list of other demands it will save the netcat output to a file. I then close netcat and ensure the file it is writing to is no longer in use. delimit and deliver.

    While this method works sometimes but not too often, it wont connect to the IP fast enough to save the data to the file so the file comes up empty.

    The solution I am looking for but cant seem to get to work is run something like LUASocket and have it stream. The first issue I found with LUASocket is if data doesn't load in its timely manor it will freeze until it sees data. The second issue I noticed is the ridiculous demands I have been calling for it to do are all on hold. The last issue I found is this is all good in theory but on demand will not connect to the host IP.

    A second thought I had is run netcat with out closing it and every now and again reach in and pick out a line from the file its being saved to. AMS doesn't seem to like to open files in use and for some reason I cant get io.open to work.

    Any help or other options would be greatly appreciated.


  • #2
    Im not going to get too much into detail changing my code but I did find a solution running On Timer

    Code:
    if netcat == 20 then
    netcat = File.Run("AutoPlay\\Scripts\\Raw.bat", "", "", SW_HIDE, false);
    else
    netcat = netcat +1; 
    end
    each timer cycle runs one second. On the 20th cycle it will run my batchfile which deletes the Stream.txt that is outputted from netcat that is called upon in the script so the file doesn't get too big.

    Code:
    local inp = assert(io.input (_SourceFolder.."\\AutoPlay\\Scripts\\Stream.txt"));
    local f = inp:read("*a");
    local Streamin = {};
    local Streamer = {};
    for line in string.gmatch(f, '([^\r\n]+)' ) do
     Streamin[#Streamin + 1] = line;
     end
     if Streamin[#Streamin] ~= nil then
    for dev in string.gmatch( Streamin[#Streamin], '([^,]+)' ) do
     Streamer[#Streamer + 1] = dev;
    end
    -- Do stuff with your newly formed Streamer[x] table
    end
    end
    end
    end

    Comment

    Working...
    X