Raised This Month: $12 Target: $400
 3% 

socket_open - error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Dead-Master
Junior Member
Join Date: Sep 2007
Old 05-13-2009 , 14:38   socket_open - error
Reply With Quote #1

#include <amxmod>
#include <sockets>

public plugin_init() {
register_plugin("http","1.0","test socket")
return PLUGIN_CONTINUE
}

public client_connect(id)
{
new sock = -1
new err
new readBuffer[2048]

sock = socket_open("127.0.0.1", 81, SOCKET_TCP, err)
server_print("%d", err)
socket_send(sock, "GET: http://127.0.0.1/index.php^r^n", 512)
socket_send(sock, "Host: 127.0.0.1^r^n^r^n", 512)
socket_recv(sock,readBuffer,204
server_print("%s", readBuffer)
socket_close(sock)
return PLUGIN_CONTINUE
}
*********************************************
server_print("%d", err)
always err = 0
If port open or port close
use amxx 1.8.1

what i do not so ?
Dead-Master is offline
Bugsy
AMX Mod X Moderator
Join Date: Feb 2005
Location: NJ, USA
Old 05-13-2009 , 19:12   Re: socket_open - error
Reply With Quote #2

1. Default HTTP port is 80 (unless the site is configured otherwise)
2. You have the HTTP request formatted incorrectly.
3. You should send the entire HTTP request in 1 packet
4. You are trying to receive data immediately after sending it. No web server will respond that fast.

Untested
PHP Code:
new g_Socket;

public 
SendRequest()
{
    new 
iError;
    
g_Socket socket_open"127.0.0.1" 80 SOCKET_TCP iError );

    if( 
g_Socket && !iError )
    {
        static 
szPacket[256];

        
formatexszPacket 255 "GET /index.php HTTP/1.1^r^nHost: 127.0.0.1^r^nConnection: close^r^n^r^n" );

        
socket_sendg_Socket szPacket strlen(szPacket) );

        if( !
task_exists5511 ) )
            
set_task0.25 "RecvData" 5511 __"b" );
    }
}

public 
RecvData()
{
    static 
szData[1024];

    if ( 
socket_changeg_Socket ) )
    {
        
socket_recvg_Socket szData 1023 );
        
        if ( 
strlenszData ) )    
        {
            
server_printszData );
            
szData[0] = 0;

            
/*if ( containi( szData , "make it stop" ) > -1 )
            {
                remove_task( 5511 );
                socket_close( g_Socket );
            }*/
        
}
    }

__________________

Last edited by Bugsy; 05-13-2009 at 21:41.
Bugsy 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:47.


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