View Single Post
HLM
Senior Member
Join Date: Apr 2008
Location: C:\WINDOWS\System32
Old 05-11-2019 , 02:10   Re: Module: Threaded Sockets
Reply With Quote #64

Hello, I was looking at this module for its threaded sockets function as I am making a webchat/realtime chat app, I was having issues as even AMXX 1.9 sockets caused me +30ms ping in order to read from the socket in a timely manner (0.5s task/thinking entity)

When trying to run this module, I ran into issues creating the socket.. I don't think that the developer is around anymore, but hopefully someone in the AMXX community has an alternative to get 'working threaded sockets' under AMXX.

This is the code I am trying.

PHP Code:
public Socket_Connect()
{

    new 
hostname[33];
    
get_cvar_string("hostname"hostnamecharsmax(hostname));

    
copy(server_namecharsmax(server_name), hostname);
    
//format(g_ServerAddress, charsmax(g_ServerAddress), "0.0.0.0:27000");

    
CheckBot();

    
g_socket socket_create_t();

    if((
socket_open_t(g_socket"M.Y.I.P."32650SOCKET_TCP"Open_Socket")) < 0)
        
server_print"ERROR: Could not open Socket. %d"socket_get_last_error_t(g_socket) );
    else 
server_print("Opening socket...");

}

public 
Socket_OpeniThreadStateiReturn)
{
    
server_print("Socket_Open");
    if( 
iReturn )
    {
        
log_amx"ERROR: Could not open Socket. Error[%d] : %d"iReturnsocket_get_last_error_t(g_socket) );
    }
    else
    {
        new 
packet[256];
        
formatex(packetcharsmax(packet), ".login ^"%s^"^n.server %s^n.password Some Unique String^n"server_nameg_ServerAddress);

        if((
socket_send_t(g_socketpacketcharsmax(packet), "Socket_Send")) < 0)
        {
            
server_print("Could not send data.");
        }
    }
}
public 
Socket_SendiThreadStateiReturn )
{
    if (
iReturn 0)
    {
        
log_amx"ERROR: Error Sending Data. Error[%d] : %d"iReturnsocket_get_last_error_t(g_socket) );
    }
    else
    {
        if ((
socket_recv_t(g_socket"Socket_Receive"512)) < 0)
        {
            
server_print("Issues recieving data");
        }
    }
}
public 
Socket_ReceiveiThreadStateiReturnszRecvData[], iRecvDataLen )
{
    if(
iReturn == 0)
    {
        
server_print("Socket Closed!");
        
socket_close_t(g_socket"Socket_Close");
    }
    else if (
iReturn 0)
    {
        
server_print"ERROR: Error while receiveing data. Error[%d] : %d"iReturnsocket_get_last_error_t(g_socket) );
        
socket_close_t(g_socket"Socket_Close");
    }
    else
    {
        
server_print("Successfully Received Data[%d] : Received - %d "iRecvDataLenszRecvDatastrlen(szRecvData));
    }
}
public 
Socket_CloseiThreadStateiReturn )
{
    
socket_destroy_t(g_socket);

and the response.
Code:
In socket_create_t, creating thread obj
In socket_create_t, creating thread
In socket_create_t, attaching thread
In socket_create_t, adding thread item thread
in CThreadedSocketManager::AddItemToList, before
Start ((nil)) ((nil)) END
in CThreadedSocketManager::AddItemToList, Adding item to list with id 0 Addr 0x99473d0
item-Pev = (nil) end : (nil)
item-Pev = (nil) end : (nil)
in CThreadedSocketManager::AddItemToList, after
Start (0x99473d0) | (nil) (0x99473d0) (nil) | (0x99473d0) END
In socket_create_t, returning cast thread 160723920[4]
In Threadmain, arg - 160723920
In ThreadMain, state is 7
In socket_open_t, De-Casting rc
In socket_open_t, De-Casting rc 160723920[4]
In socket_open_t, Assigining hn 66.151.244.170[66.151.244.170]
In socket_open_t, Assigining port
In socket_open_t, Assigining proto
In socket_open_t, Assigining fid
ERROR: Could not open Socket. -1
__________________
+|- KARMA Respectively

HLM is offline