well to do this, you have to introduce a protocol how to format the data
sent over tcp. this is what http does. You could use a
JSONStream https://github.com/dominictarr/JSONStream
where you just pipe the it to/from the socket and your json object could be
like: {filename:'a string of file', file:myFileBuffer.toString('ensoding
you like')}
Am Freitag, 8. März 2013 08:45:54 UTC+1 schrieb Thorsten Moeller:
>
> Security isn't the big thing here as it would be a kind of strictly
> internal file distribution between a central server and some other servers
> in the same network. No external access here.
>
> The problem i really have is to do some simple filecopy via socket from
> one server to another. These are very small files, so buffering might also
> not be a problem.
>
> Both informations are present on the sending server. I managed to send the
> filename, but i didn't managed to send the file-data right after it.
>
> I did not found out correctly, how to tell the receiving side that the
> filename is done (guess it is sending an "end") and that now the data is
> coming. All of this should be done via tcp net sockets.
>
> Doing this separately in dedicated connection it works, but not with a
> single connection.
>
> Thorsten
>
> Am Donnerstag, 7. März 2013 17:32:37 UTC+1 schrieb Tim Dickinson:
>>
>> This is to say that he is using node 0.9.x
>> Also as @greelgorke said, a large file will bring up problem with
>> keeping the data in memory.
>>
>> Streaming the data to a tmp file "/tnp/random-name" is the best bet.
>> it removes any complexity that might come up then trying to pipe the data
>> back into a file.
>>
>> @Thorsten Moeller You should really think about getting the name of the
>> file before you write any data to it. You will have a stronger program if
>> you do.
>>
>> On Thursday, March 7, 2013 10:15:04 AM UTC-5, Luke Arduini wrote:
>>>
>>> @tim you're thinking of streams as just file-related things
>>>
>>> thorsten -
>>>
>>> Using the new stream class you can do:
>>>
>>> var stream = new Stream.Readable()
>>> stream.push(null)
>>> stream.push('your data and stuff')
>>>
>>> when you're ready for a file
>>>
>>> stream.pipe(fs.createWriteStream('outputfile'))
>>>
>>> keep in mind data events wont get emitted without a listener in new
>>> streams, for better/worse depending on what you're trying to do
>>>
>>>
>>> On Thu, Mar 7, 2013 at 9:43 AM, Tim Dickinson <[email protected]>wrote:
>>>
>>>> I dont really understand what your trying to do. You cant create a
>>>> write stream without a file name. You could create a random file name and
>>>> then rename it once you have the real file name.
>>>>
>>>>
>>>> On Thursday, March 7, 2013 9:35:00 AM UTC-5, Thorsten Moeller wrote:
>>>>>
>>>>> Hi,
>>>>>
>>>>> i am creating a writestream on a server connection event using a path
>>>>> join of a fix path and a variable for the filename. As the filename is
>>>>> not
>>>>> known on server connection event (sent later via connection data event) ,
>>>>> it is empty and therefore not working afterwards, producing errors
>>>>> (connot
>>>>> open file).
>>>>>
>>>>> Is there a way to handle this more dynamically?? Perhaps creating the
>>>>> stream first like an global object and later set the filename and then
>>>>> using the stream via something like a method???
>>>>>
>>>>>
>>>>> Regards
>>>>>
>>>>> Thorsten
>>>>>
>>>> --
>>>> --
>>>> Job Board: http://jobs.nodejs.org/
>>>> Posting guidelines:
>>>> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nodejs" group.
>>>> To post to this group, send email to [email protected]
>>>> To unsubscribe from this group, send email to
>>>> [email protected]
>>>> For more options, visit this group at
>>>> http://groups.google.com/group/nodejs?hl=en?hl=en
>>>>
>>>> ---
>>>> You received this message because you are subscribed to the Google
>>>> Groups "nodejs" group.
>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>> an email to [email protected].
>>>> For more options, visit https://groups.google.com/groups/opt_out.
>>>>
>>>>
>>>>
>>>
>>>
--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
---
You received this message because you are subscribed to the Google Groups
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.