• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

[NODEJS] Socket.io event triggered

Joined
May 27, 2008
Messages
3,628 (0.62/day)
System Name Ultra 64
Processor NEC VR4300 (MIPS R4300i)
Motherboard proprietary design
Cooling Fanless aircooled
Memory 4.5MB 250 MHz RDRAM
Video Card(s) 62.5 MHz Reality Coprocessor
Storage 32 - 512 Mbit ROM Cartridge
Display(s) 720x576
Case Clear Blue Funtastic
Audio Device(s) 16-bit CD quality
Power Supply proprietary design
Mouse N64 mouse for use with N64DD
Keyboard N64 keyboard for use with N64DD
Im adding an interpretable file transfer between two NodeJS instances for our application at work.

The laptops connects to the VPN. Currently the trouble were having is it tries to sync up a rather large zip in one go and if the laptop looses WiFi the sync fails. Both the Server and laptop Node instances use socket.io for their portals so im going to chop the file up into chunks, use socket.io to send the chunks and re build it on the server. Then if the WiFi drops the server just drops the chunk if its not complete and asks for it again when the laptop reconnects.

Now my question is do the socket.io events fire only when all data is received? Im using it at the moment to send very small JSON objects the data that will be sent will be up-to 5 meg so much larger. How does socket.io handle situations where the connection is lost before all the data is received on a pending event? Will it drop it and clean up or will it hold on to it?

Hope that all makes sense. Thanks guys n gals.
 
Joined
Jan 9, 2010
Messages
481 (0.09/day)
Location
Kansas
System Name Late 2013 rMBP 13'' w/ 250 GB SSD
Display(s) Dell P2416D @ 2560x1440 & Dell U2211H @ 1920x1080
Audio Device(s) NuForce uDAC-2 w/ Klipsch Promedia 2.1 & Sennheiser HD595
Mouse Logitech G400 @ 1600 DPI
Keyboard Razr Black Widow
Software OS X

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,031 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
I would send a small (=quick) packet for the beginning and end of the transfer, including byte count to send and byte count received, so you can check on both ends.

Not sure if you even need socket io (yes i know what it is and have used it before). just regular http post requests fired from js should be fine.

How do you plan on splitting the file? JS has no filesystem access

http://www.w3.org/TR/FileAPI/ with limited browser support
 
Joined
May 27, 2008
Messages
3,628 (0.62/day)
System Name Ultra 64
Processor NEC VR4300 (MIPS R4300i)
Motherboard proprietary design
Cooling Fanless aircooled
Memory 4.5MB 250 MHz RDRAM
Video Card(s) 62.5 MHz Reality Coprocessor
Storage 32 - 512 Mbit ROM Cartridge
Display(s) 720x576
Case Clear Blue Funtastic
Audio Device(s) 16-bit CD quality
Power Supply proprietary design
Mouse N64 mouse for use with N64DD
Keyboard N64 keyboard for use with N64DD
Awesome links thanks.

I'm using socket.io as both the server and client have it. By client I mean the small NodeJS server on the laptop, not a browser so I handle chopping the files up and re-building them on both ends using NodeJS's FileSystem module. I've currently got a working prototype. The Client keeps track of how much has been uploaded. It will hit the server when connected with details on the file to upload and the data-chunk. The server inserts this data into the file specified at the location in the file specified then hits the client back to tell the client it has done it, with info on whether it was successful. Once the client receives this complete message it updates its database on how much has been successfully sent and repeats with the next chunk. This means that if the connection is lost anywhere in that process before the complete message is sent it doesn't matter. Even if that data has been successfully added to the file as it will be resent the next time the client connects as it didn't receive a successful complete message back. This works quite well with me rather violently pulling my Ethernet cable during the process and at the end i still get a complete, uncorrupted zip file.
 

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,031 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
So you run nodeJS on both ends of your connection? Which means you could run any other custom software for the transfer?

rsync --partial + automatic restart when rsync dies wont work for you ?
 
Joined
May 27, 2008
Messages
3,628 (0.62/day)
System Name Ultra 64
Processor NEC VR4300 (MIPS R4300i)
Motherboard proprietary design
Cooling Fanless aircooled
Memory 4.5MB 250 MHz RDRAM
Video Card(s) 62.5 MHz Reality Coprocessor
Storage 32 - 512 Mbit ROM Cartridge
Display(s) 720x576
Case Clear Blue Funtastic
Audio Device(s) 16-bit CD quality
Power Supply proprietary design
Mouse N64 mouse for use with N64DD
Keyboard N64 keyboard for use with N64DD


Hard for something to work for you when you don't realise it exists.

Judging by https://github.com/mattijs/node-rsync rsync is some built in command(Assuming the linked module is a wrapper for it)? Ill have to look into it a bit more. Well that was a day wasted.

EDIT: One system in windows based the other linux, will rsync still be a possible solution? Still have to look into it. What if the laptop goes to sleep half way through? The current solution will successfully continue, could rsync?
 
Last edited:

W1zzard

Administrator
Staff member
Joined
May 14, 2004
Messages
27,031 (3.71/day)
Processor Ryzen 7 5700X
Memory 48 GB
Video Card(s) RTX 4080
Storage 2x HDD RAID 1, 3x M.2 NVMe
Display(s) 30" 2560x1600 + 19" 1280x1024
Software Windows 10 64-bit
There is rsync for win32. rsync will continue when returning from sleep. Yes it's a command line tool on Linux
 
Top