It does not support a binary transfer (null byte)?
@EDIT
suggestions:
- Add the "iThreadHandle" param on callbacks or a array to pass custom data (if you do this, you could remove "iThreadState" and not implement "iThreadHandle")
- Remove param "protocol", only support TCP.
- iRecvDataLen is bytes received
- Check callback valid public fuction
- Support null bytes for recv
@EDIT2
win2008:
50% CPU usage on STATE_READ
code:
Spoiler
PHP Code:
#include <amxmodx> #include <sockets>
new const upload_file[] = "test.txt"
new const upload_host[] = "localhost" new const upload_script[] = "/screenshot/upload.php"
new g_SockThread
public plugin_init() { register_plugin("Test Upload", "1.0", "Destro")
set_task(3.0, "start_upload") }
public start_upload() { g_SockThread = socket_create_t()
if((socket_open_t(g_SockThread, upload_host, 80, SOCKET_TCP, "open_socket")) < 0 ) { server_print("ERROR: Could not open Socket.") return }
server_print("Trying to open connection...") }
public open_socket(thread_state, result) { if(result < 0) { server_print("ERROR: Could not open Socket. Error[%d] : %d", result, socket_get_last_error_t(g_SockThread)) } else { new fp = fopen(upload_file, "rb") if(!fp) { server_print("ERROR: Coulds not open upload File [%s]", upload_file) return }
new buff[2048], data[1800], packet_size, len/*, fsize*/
/*fseek(fp, 0, SEEK_END) new fsize = ftell(fp) fseek(fp, 0, SEEK_SET)*/
len = copy(data, charsmax(data), "--642865735weasdasdwe4285675865^r^nContent-Disposition: form-data; name=^"file^"; filename=^"asd^"^r^n^r^n")
len += fread_blocks(fp, data[len], charsmax(data) - len - 50, BLOCK_CHAR)
len += copy(data[len], charsmax(data) - len, "^r^n--642865735weasdasdwe4285675865--^r^n")
public plugin_init() { register_plugin(PLUGIN, VERSION, AUTHOR) register_srvcmd("test_send", "test_send") }
public test_send() { new SOCKET:socket = socket_create(SOCK_TYPE_TCP, 0) socket_connect(socket, "127.0.0.1", 80) }
public fw_sockConnected(SOCKET:socket, customID) { new packet[256] formatex(packet, 255, "%c%c%c%c", 0x00, 0x00, 0x00, 0x00) new len = socket_send(socket, packet) log_amx("Sending packet len: %d", len) }
When im using "test_send", it gives me answer "Sending packet len: 0" - that means it ignores all my null bytes. Tested it on windows server with web. Could you please resolve this issue?
Thx, this worked for me! But the disadvantage is that we should always count exact number of bytes in code to send them. And if i need, for example, 3 null bytes at the end, it is required to make len + 3 to send them correctly.
Please, update sockets_async.inc to this code. It allows the module to autoload instead of writing it in modules.ini.
Also, ive found that if 2 or more plugins are using this module there are several memory collisions between them. It means that if im sending info in second plugin, then im recving it in first of them that has fw_sockReadable hook. May be, im doing smth wrong, but in native amxx modules there are not collisions between plugins.
Hi, in last version of this module in LINUX there is always error 115 (SOCK_INPROGRESS) at crear connection (when im using socket_connect function in plugin. Ive tried to overpass that error by modifying the source of module but now after socket_create nothing happenes, seems, that socket is always non-writable while in windows server this works fine.
Could you please fix this issue?
This module eliminates looping, hidden looping, entity thinks in plugin as well as in the main thread.
Destro, you are just continuously looping and checking if there is any change in state of the socket, you don't know the exact time when your asyn sockets respond to your command(connect, send,...) similar to the includes aforementioned and hence looping becomes inevitable. But in game engines, we cannot afford that many number of false checking in loops on the same thread on which main HLDS functions are running (that too on StartFrame()). So what my module actually does is, it separates these loops from the main thread and keeps them on a Child Thread, eliminating false checks on the main thread. These child threads will inform the main thread when there is a change in state of the socket and executes a corresponding forward.
Your module is a module level implementation of what Bugsy's includes and others does and is more efficient (ofcourse). You are free to start a new thread in Module Section for your Async-Sockets, but its different from mine (atleast in theory).
Shooting King,
Could you please make your API more useful?
I mean that for example we are sending multiply socket queries in one time, how can i understand in callback which one is answering of them? There is no way in plugin to add custom information in callback (for example, playerID for which im sending socket query) and in ur examples u are using single global variable for that purpose which is highly unappreciated.
In AMX there is set_task function that allows us to send custom information in callback, could you upgrade your module and API to something similar? Or may be u can use Destro API, it is also not bad.
BTW:
Quote:
suggestions:
- Add the "iThreadHandle" param on callbacks or a array to pass custom data (if you do this, you could remove "iThreadState" and not implement "iThreadHandle")