Raised This Month: $32 Target: $400
 8% 

Sending a large file with sockets.


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Ramono
Veteran Member
Join Date: Nov 2005
Location: Netherlands
Old 09-17-2010 , 11:05   Sending a large file with sockets.
Reply With Quote #1

Hello,

I'm currently trying to send over a large file over "sockets_hz" module, but the functions used which creates the problem should be no different then the default "sockets" module

I currently have some kind of 'mini webserver' and it propperly creates headers error responses etc etc, it can send small files aswell. but whenever I want to send a large file over it to a client with a low download speed the client recieves the file corrupted(smaller in size as the original).

Code:
public sendfile(file[],socket) {
	new buffer[1024]
	server_print(file)
	
	new fp_read = fopen(file, "rb") 
	fseek(fp_read, 0, SEEK_END)
	new fsize = ftell(fp_read);
	fseek(fp_read, 0, SEEK_SET);
	
	** ALOT OF HTTP HEADER STUFF HERE(also uses buffer[1024] and fsize)**
	
	// File reading code by ot_207
	new readsize 
	
	for (new j = 0; (j*(1024)) < fsize; j++) { 
		readsize = fread_blocks(fp_read, buffer, 1024, BLOCK_CHAR); 
		socket_send2(httpsocket,buffer,readsize)
	} 
	
	fclose(fp_read) 
	socket_close(socket)
}
Right now i just spam the socket_send in parts of 1024bytes untill the end of the file is reached, This might be the problem because the client isnt ready for the next packet yet. but I cant seem to figure out how to do this in any other way apart from lowering the speed for ALL clients, which I am not gonna do.

Thanks,
-Ramon(o)
__________________
Um, hi.

Last edited by Ramono; 09-18-2010 at 07:16.
Ramono is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 09-17-2010 , 17:37   Re: Sending a large file with sockets.
Reply With Quote #2

http://www.amxmodx.org/funcwiki.php?go=func&id=1035
http://forums.alliedmods.net/showthread.php?t=130243
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
Ramono
Veteran Member
Join Date: Nov 2005
Location: Netherlands
Old 09-18-2010 , 04:30   Re: Sending a large file with sockets.
Reply With Quote #3

Updated!

Thanks, that works alot faster,

But because of that it makes the main problem even worse as it sends the data even faster now
__________________
Um, hi.
Ramono is offline
Mati_
Member
Join Date: Sep 2010
Old 09-18-2010 , 12:42   Re: Sending a large file with sockets.
Reply With Quote #4

Would it be possible to send larger packets, and pause it for some milliseconds each time? Like a "senseless" for (new x=0; x<=9999; x++) {} at the end of the for loop?
Mati_ is offline
Ramono
Veteran Member
Join Date: Nov 2005
Location: Netherlands
Old 09-18-2010 , 17:00   Re: Sending a large file with sockets.
Reply With Quote #5

Solution found on IRC by "txdv"
socket_send returns -1 on a failure
__________________
Um, hi.
Ramono is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:46.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode