flat assembler
Message board for the users of flat assembler.

Index > Windows > Winsock - what's best way to send/recv files?

Author
Thread Post new topic Reply to topic
OzzY



Joined: 19 Sep 2003
Posts: 1029
Location: Everywhere
OzzY 14 Aug 2007, 20:56
Hello!
I want to create a simple file server and client.
What's the best way to handle the data (and the size of the data) between the sockets?
Post 14 Aug 2007, 20:56
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7103
Location: Slovakia
vid 14 Aug 2007, 23:19
best way is not simple Razz
Post 14 Aug 2007, 23:19
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3174
Location: Denmark
f0dder 15 Aug 2007, 11:33
Depends on your needs and usage... are you going to have a lot of simultaneous clients? Yes, then I/O Completion Ports. Are you only going to work in a LAN? If yes, UDP instead of TCP might be an option for slightly higher throughput. If you're only going to have very few simultaneous connections, you could even use a thread per connection and blocking sockets.
Post 15 Aug 2007, 11:33
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 15 Aug 2007, 13:03
TransmitFile api efficiently sends files across a socket connection.
Post 15 Aug 2007, 13:03
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3174
Location: Denmark
f0dder 15 Aug 2007, 14:30
TransmitFile has a limit on number of concurrent transfers, though, if you aren't running a server version of NT... and how would you keep a progress indicator updated with TransmitFile? Smile
Post 15 Aug 2007, 14:30
View user's profile Send private message Reply with quote
r22



Joined: 27 Dec 2004
Posts: 805
r22 15 Aug 2007, 17:45
The SERVER end of a file server doesn't need to show progress information (i think a log with Tranfer Begin and Transfer End time stamps would probably be sufficient), just the clients, which would need to be sent the file size in advance, would show transfer progress.

As for the number of concurrent transfers, a limit on them would probably be best, you'd start bottlenecking on your HD with two or three concurrent reads on larger files.
Post 15 Aug 2007, 17:45
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade 15 Aug 2007, 21:58
I would have to agree with the TransmitFile suggestion. It's what i used in a small httpd i made for windows, and performance wise it seems to do the job damn well.
Post 15 Aug 2007, 21:58
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3174
Location: Denmark
f0dder 16 Aug 2007, 12:55
It can be useful enough to be able to check completion status server-side - especially when dealing with large files. But again, it all really comes down to what you need.

TransmitFile has the obvious advantage of making "as few user<>kernel switches as possible", those are sorta expensive. Especially if you have a busy server with lots of clients. If I was coding a httpd server, I'd use it too - but possibly using something else for larger files, to have a bit more control.
Post 16 Aug 2007, 12:55
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 16 Aug 2007, 13:20
TransmitFile does not allow the server to implement byte ranges and hence, the server will not support resuming downloads.
Post 16 Aug 2007, 13:20
View user's profile Send private message Reply with quote
f0dder



Joined: 19 Feb 2004
Posts: 3174
Location: Denmark
f0dder 16 Aug 2007, 14:01
LocoDelAssembly: I think byte ranges could be implemented if you use the OVERLAPPED structure that TransmitFile takes as an arg?
Post 16 Aug 2007, 14:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4623
Location: Argentina
LocoDelAssembly 16 Aug 2007, 14:42
Quote:
You can use lpOverlapped to specify an offset within the file at which to start the file data transfer by setting the Offset and OffsetHigh member of the OVERLAPPED structure. If lpOverlapped is NULL, the transmission of data always starts at the current byte offset in the file.

Yes Embarassed
Post 16 Aug 2007, 14:42
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.