Raised This Month: $ Target: $400
 0% 

Sending a large file with sockets.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
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
 



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 14:00.


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