I can't seem to get the sockets to work properly, whats wrong with this code (new to socket and serious amxx coding), I don't get any errors and file is created but I don't get hold of the text from the host:
PHP Code:
#include <amxmodx>
#include <sockets>
#define MAX_TEMP 128
new strDemFile[ MAX_TEMP ], strBuffer[ MAX_TEMP * 100 ];
public plugin_init( )
{
register_plugin( "Download text testing", "1.0", "OFFBEAT" );
register_clcmd( "say /download", "Download" );
new strTemp[ MAX_TEMP ];
get_localinfo( "amxx_datadir", strTemp, MAX_TEMP - 1 );
format( strTemp, MAX_TEMP - 1, "%s/Downloads", strTemp );
if( !dir_exists( strTemp ) )
mkdir( strTemp );
formatex( strDemFile, MAX_TEMP - 1, "%s/dled_text.txt", strTemp );
}
public Download( )
{
if( file_exists( strDemFile ) )
delete_file( strDemFile );
new strHost[ MAX_TEMP ] = "kz-scandinavia.com";
new strFile[ MAX_TEMP ] = "demos_se.txt";
new error = 0, strMessage[ MAX_TEMP * 2 ];
new error_socket = socket_open( strHost, 80, SOCKET_TCP, error );
formatex( strMessage, ( MAX_TEMP * 2 ) - 1, "GET /%s HTTP/1.1^nHost: %s^r^n^r^n", strFile, strHost );
socket_send( error_socket, strMessage, ( MAX_TEMP * 2 ) -1 );
set_task( 0.2, "Recieve", error_socket );
return PLUGIN_CONTINUE;
}
public Recieve( const Socket )
{
socket_recv( Socket, strBuffer, ( MAX_TEMP * 100 ) - 1 );
new file = fopen( strDemFile, "at" );
fputs( file, strBuffer );
fclose( file );
server_print( strDemFile );
return PLUGIN_CONTINUE;
}