Raised This Month: $ Target: $400
 0% 

[Sockets]: Download a text for server usage


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
OFFBEAT
Junior Member
Join Date: Feb 2011
Location: Sweden
Old 08-01-2011 , 14:38   [Sockets]: Download a text for server usage
Reply With Quote #1

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 strDemFileMAX_TEMP ], strBufferMAX_TEMP 100 ];

public 
plugin_init( )
{
    
register_plugin"Download text testing""1.0""OFFBEAT" );
    
    
register_clcmd"say /download""Download" );
    
    new 
strTempMAX_TEMP ];
    
get_localinfo"amxx_datadir"strTempMAX_TEMP );
    
formatstrTempMAX_TEMP 1"%s/Downloads"strTemp );
    
    if( !
dir_existsstrTemp ) )
        
mkdirstrTemp );
    
    
formatexstrDemFileMAX_TEMP 1"%s/dled_text.txt"strTemp );
}

public 
Download( )
{
    if( 
file_existsstrDemFile ) )
        
delete_filestrDemFile );
    
    new 
strHostMAX_TEMP ] = "kz-scandinavia.com";
    new 
strFileMAX_TEMP ] = "demos_se.txt";
    new 
error 0strMessageMAX_TEMP ];
    
    new 
error_socket socket_openstrHost80SOCKET_TCPerror );
    
    
formatexstrMessage, ( MAX_TEMP ) - 1"GET /%s HTTP/1.1^nHost: %s^r^n^r^n"strFilestrHost );
    
    
socket_senderror_socketstrMessage, ( MAX_TEMP ) -);
    
    
set_task0.2"Recieve"error_socket );
    
    return 
PLUGIN_CONTINUE;
}

public 
Recieve( const Socket )
{
    
socket_recvSocketstrBuffer, ( MAX_TEMP 100 ) - );
    
    new 
file fopenstrDemFile"at" );
    
fputsfilestrBuffer );
    
fclosefile );
    
    
server_printstrDemFile );
    
    return 
PLUGIN_CONTINUE;


Last edited by OFFBEAT; 08-01-2011 at 20:51.
OFFBEAT 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 03:27.


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