Raised This Month: $ Target: $400
 0% 

Problemas con Sockets


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 12-18-2012 , 16:37   Problemas con Sockets
#1

Hice un chat entre servidores pero no funciona.

Lo que falla es el envío de datos, al menos es el único registro de problema que aparece. Ven algo mal?. Tengo otros plugins con sockets pero nada entre servidores por ende no sé que puede ser.

PHP Code:
#include <amxmodx>
#include <engine>
#include <sockets_hz>

#define PLUGIN "Sockets: Multi Chat"
#define VERSION "1.0"
#define AUTHOR "gladius"

new g_hSocket;
new 
g_iPort;

new 
g_msgSayText;
new 
g_MaxPlayers;

new 
g_szIPs[2][40] =
{
    
"201.238.222.69:27018",
    
"201.238.222.69:27019"
}
new 
g_server_ip[40]

public 
plugin_init() 
{
    
register_plugin(PLUGINVERSIONAUTHOR);
    
    
get_user_ip(0g_server_ipsizeof g_server_ip 1);
    
    
g_iPort get_cvar_num("port"); // Algunos usan #define DEFAULTPORT 18107 //Game: find why the port number is  18107
    
new iError
    
g_hSocket socket_listen("127.0.0.1"g_iPortSOCKET_TCPiError);
    
    if(
g_hSocket <= || iError
    { 
        
server_print("Error listening; Socket=%d Error=%d"g_hSocketiError); 
        
log_to_file("socketsss.txt""Error listening; Socket=%d Error=%d"g_hSocketiError); 
    } 
    
/*else 
    { 
        server_print("Listening on %d" , g_hSocket); 
        //log_to_file("socketsss.txt", "Listening on %d" , g_hSocket);  
    }*/
    
socket_unblock(g_hSocket);
    
    
g_MaxPlayers get_maxplayers();
    
    
g_msgSayText get_user_msgid("SayText");
    
register_message(g_msgSayText"Message_SayText");
    
    new 
iEntity create_entity("info_target");
    if(
is_valid_ent(iEntity))
    {
        new const 
szClassName[] = "SocketReader";
        
        
entity_set_string(iEntityEV_SZ_classnameszClassName);
        
entity_set_float(iEntityEV_FL_nextthinkget_gametime() + 0.1);
        
        
register_think(szClassName"FwdSocketEntityThink");
    }
    else
    {
        
server_print("socketsss.txt""Could not create socket reader entity.");
        
log_to_file("socketsss.txt""Could not create socket reader entity.");
        
plugin_end();
    }
}

public 
plugin_end() 

    if(
g_hSocket 0)
    {
        
socket_close(g_hSocket);
        
g_hSocket 0;
    }


public 
Message_SayText() 

    new 
szChannel[60];
    
get_msg_arg_string(2szChannelcharsmax(szChannel));
    
    if(
equal(szChannel"#Cstrike_Chat"13)) 
    { 
        if(
equal(szChannel"#Cstrike_Chat_All")) 
        {             
            new 
iErrorhSocket;
            new 
i;
            new 
IP[40], Port[8];
            for(
0sizeof g_szIPsi++)
            {
                if(
equal(g_server_ipg_szIPs[i]))
                    continue;
                    
                
strtok(g_szIPs[i], IPsizeof IP 1Portsizeof Port 1':');    
                
                
hSocket socket_open(IPstr_to_num(Port), SOCKET_TCPiError);
                if(
hSocket <= || iError)
                { 
                    
server_print("Error opening; Socket=%d Error=%d IP=%s Port=%d"hSocketiErrorIPstr_to_num(Port));
                    
log_to_file("socketsss.txt""Error opening; Socket=%d Error=%d IP=%s Port=%d"hSocketiErrorIPstr_to_num(Port));
                    continue;
                }
                
//server_print("[%d] Socket Connected", hSocket); 
                //log_to_file("socketsss.txt", "[%d] Socket Connected", hSocket);
                
                
socket_send(hSocketszChannelsizeof szChannel 1);
                
socket_close(hSocket);
            }
        }
    } 
}

public 
FwdSocketEntityThinkiEntity )
{
    new 
hSocket socket_accept(g_hSocket); 
    
    if(
hSocket || socket_change(g_hSocket1))
    {
        
//socket_unblock(hSocket);
        //server_print("Connection successfully accepted on %d, new socket=%d", g_hSocket, hSocket); 
        //set_task(1.0, "TaskReceiveData", hSocket);
        //log_to_file("socketsss.txt", "Connection successfully accepted on %d, new socket=%d", g_hSocket, hSocket);
        
        
server_print("Connection successfully accepted on %d"g_hSocket);
        
log_to_file("socketsss.txt""Connection successfully accepted on %d"g_hSocket);
        
Task_ReceiveData(g_hSocket)
    }
    else
    {
        
//server_print("Error accepting connection on %d" , g_hSocket); 
        //log_to_file("socketsss.txt", "Error accepting connection on %d" , g_hSocket); 
    
}
    
entity_set_float(iEntityEV_FL_nextthinkget_gametime() + 0.1);
}

public 
Task_ReceiveData(hSocket)
{
    new 
szData[1024]; 
    
socket_recv(hSocketszDatacharsmax(szData));
    
    
server_print("Data: %s"szData);
    
log_to_file("socketsss.txt""Data: %s"szData);
    
    for(new 
ig_MaxPlayersi++)
    {        
        
message_begin(MSG_BROADCASTg_msgSayText
        { 
            
write_byte(i
            
write_string(szData
            
write_string(""
            
write_string(""
        }
        
message_end()
    }

Log
Code:
L 12/18/2012 - 02:00:24: Error opening; Socket=-1 Error=3 IP: 201.238.222.69 Port: 27019
* Socket=-1 - Error.
* Error = 3 - couldn't connect to given hostname:port .

Estaba tratando de conectarme desde el server con puerto 27018 al 27019.


Ya revisé el plugin de Exolent y el plugin de Hacknizer, mi plugin es bastante similar a ellos solo se podría decir que cambia en la forma que metemos varias ips, por ahora lo tengo así ya que busco hacerlo funcionar primero.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 12-18-2012 at 16:48.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
 



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 06:57.


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