View Single Post
Author Message
joropito
AlliedModders Donor
Join Date: Mar 2009
Location: pfnAddToFullPack
Old 07-08-2012 , 21:49   Module: Threaded HTTP
Reply With Quote #1

This module implements an HTTP client in a threaded mode.

What is threaded?

To avoid process blocking, this technique sends the request and wait for response in asynchronous way.

At each StartFrame of hlds server, it checks if there's some pending request and in that case it checks for data in buffer.

It's implemented using a free library HappyHTTP.


How to use it?

From the plugin, call the native: thttp_request

Wait for the forward to be called: thttp_response

Just that.

Example plugin:

Code:
#include <amxmodx>
#include <thttp>

public plugin_init()
{
        register_concmd("httpget", "httpget")
}

public thttp_response(key[], data[], code, reason[])
{
        log_amx("HTTP: key:%s code:%i reason:%s data:%s\n", key, code, reason, data);
}

public httpget(id)
{
        thttp_request("thisisthekey", "www.google.com", "GET", "/search?q=alliedmods");
        return PLUGIN_HANDLED
}

public xxx(id)
{
        thttp_request("pepepe", "www.google.com", "GET", "/search?q=test");
        return PLUGIN_HANDLED
}
Attached Files
File Type: inc thttp.inc (2.2 KB, 397 views)
File Type: zip thttp.zip (53.1 KB, 343 views)
File Type: so thttp_amxx_i386.so (106.4 KB, 348 views)
__________________

Divide et vinces
approved plugins | steam account

I don't accept PM for support. Just ask on forums.
If you're looking for private work, PM me.
joropito is offline
Send a message via MSN to joropito