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

Problemas con Sockets


  
 
 
Thread Tools Display Modes
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
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 12-18-2012 , 18:22   Re: Problemas con Sockets
#2

Proba así:
socket_listen("0"...
__________________
Destro- is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 12-18-2012 , 19:22   Re: Problemas con Sockets
#3

Estás seguro?, el error proviene al mandar información, se podría decir entre servidor-cliente. No da ningún error cuando se establece el servidor.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).

gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 12-18-2012 , 19:29   Re: Problemas con Sockets
#4

a no,flashie mal xd
como leí algo de opending pense que era la parte de abrir el socket para la escucha ( listen ).

@EDIT
El problema es que estas tratando de abrir una conexión con el otro servidor y no con el otro plugin.


pd:Apenas comente me di cuenta,apreté en edit y se me corto inet.Se me corta cada 5m y me anda asta 150 veces mas lento de lo normal (2kbps).

La puta que te pario telecom y tus putas lineas de mierda que con un poquito de augo/viento se cagan las cajas la re concha de la puta madre del director/directora de telecom la puta madre y al gobierno de mierda que no controla una puta mierdaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
__________________

Last edited by Destro-; 12-18-2012 at 19:43.
Destro- is offline
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 12-18-2012 , 19:42   Re: Problemas con Sockets
#5

Ambos servidores usan el mismo plugin no hay problema en eso.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).

gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
Destro-
Veteran Member
Join Date: Jun 2010
Location: $me->location();
Old 12-18-2012 , 19:44   Re: Problemas con Sockets
#6

te estas conectando al puerto del sv no al que abriste en el plugin.
__________________

Last edited by Destro-; 12-18-2012 at 19:44.
Destro- is offline
Kiske
Veteran Member
Join Date: May 2009
Old 12-19-2012 , 00:21   Re: Problemas con Sockets
#7

No sé si lo que estás haciendo es querer aprender a usar sockets o hacer el chat entre varios servidores.
De las dos maneras, tal vez esto te pueda ayudar: https://forums.alliedmods.net/showpo...7&postcount=13
Kiske is offline
Send a message via Skype™ to Kiske
gladius
Veteran Member
Join Date: Jul 2008
Location: Santiago, Chile
Old 12-19-2012 , 00:41   Re: Problemas con Sockets
#8

Se usar Sockets pero acá en Pawn al hacer server con server me compliqué, hacerlo con web es fácil. Y como dije ya revisé ese plugin.

Destro voy a probar con unos cambios y mañana te digo.
__________________
Proyects
Kreedz Chile Mod [100%] (Fixing some details).


Last edited by gladius; 12-19-2012 at 00:41.
gladius is offline
Send a message via MSN to gladius Send a message via Skype™ to gladius
Neeeeeeeeeel.-
Some Guy Yellin'
Join Date: Jul 2010
Location: Argentina
Old 12-19-2012 , 20:24   Re: Problemas con Sockets
#9

Intentaste con el socket default?
__________________
Neeeeeeeeeel.- is offline
Send a message via Skype™ to Neeeeeeeeeel.-
 



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 07:47.


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