Skip to main content
gamedev.net
🔒 Locked

Updating/patching client files?

Started by HopeDagger Nov 7, 2004 at 8:57 PM 0 replies 500+ views
Original Post
HopeDagger
HopeDagger
I've been playing with networking on a non-serious level (y'know, an online game here and there :P), and I'm wondering how to send a file from the server's end over a TCP connection and assemble it into an actual file on the client's end. This would be used for updating client files when new updates are available from the server. I haven't been able to locate any resources about how to do this, so I'm hoping someone 'round-bouts here will shed some light on things for me. :)
hplus0603
hplus0603
If you want to do actual diffing over a number of files, you could look into the source for the "rsync" command.

If all you want to do is send data from the server to the client, and create a file on the client, I'd do something like:

On the server:

1) open file
2) get file length
3) write strlen(filename) as byte to output socket
4) write filename as bytes to output socket
5) write file length as htonl() long to output socket
6) while there's data to read:
7) read some data (say, 4k chunks, but no more than what's left)
8) write the data you read, to the network
9) when done, close the socket

On the client:

1) read one byte from input socket
2) read that many bytes for filename from input socket
3) remember to zero terminate the destination array
4) create a file named like that
5) read long (using ntohl()) from input socket
6) while there's data to receive:
7) read data from input socket (say, 4k blocks, but no more than what's left)
8) write data to the output file
9) when done, close the socket

enum Bool { True, False, FileNotFound };

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.