View Single Post
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