AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [Socket Read] (https://forums.alliedmods.net/showthread.php?t=143804)

ProIcons 11-25-2010 05:41

[Socket Read]
 
PHP Code:

new bothost,botcmd[2049];
 public 
socket_init()
{
    new 
ip[64],port,erre,user[32],pass[100]
    new 
cmd[300];
    
get_cvar_string("cm_bot_host",ip,63)
    
port get_cvar_num("cm_bot_port")
    
get_cvar_string("cm_bot_user",user,31)
    
get_cvar_string("cm_vot_pass",pass,99)
    
bothost socket_open(ip,port,SOCKET_TCP,erre)
    if (
erre == 0) {
        
remove_taskRETRY );
    
server_print("Socket Reopened");
    }
    
format(cmd,299,"USER asd^r^nPASS asd^r^n")
    
socket_send(bothost,cmd,512)
    new 
params];
    
params] = bothost;
    
set_task0.5 "socket_read" TASK_RECV params sizeofparams ) , "b" );
}
 new 
socket_status[50]
 
   public 
socket_read(botcmd[])
{
   if ( 
socket_changebothost ) )
   {
   
socket_recv(bothost,botcmd,2048)

   if (
equal(botcmd,"")) {
       
server_print("[Network] Connection with Bot has been lost");
       new 
params[9];
       
params[1] = RETRY;
       
set_task0.25 "socket_init" RETRY params sizeofparams ) , "b" );
       
remove_taskTASK_RECV );
   }
 ... 

Post Changed:D
Well i am getting a live streaming connection between the server and my bot with this script... but when i am closing the Bot, and the pawn script is trying to reenstablish connection it freezes for a while.. why that? i am closing the "retry" task when the server is connecting :P

ProIcons 11-25-2010 08:13

Re: [Socket Read]
 
Topic Changes - Please re Read

Bugsy 11-25-2010 08:39

Re: [Socket Read]
 
Try this

You can use this thread for reference: http://forums.alliedmods.net/showpos...06&postcount=4
PHP Code:

//added to be able to compile
//const TASK_RECV = 1234;

new bothost,botcmd[2049];
new 
socket_status[50]
 
public 
socket_init()
{
    new 
ip[64],port,erre,user[32],pass[100]
    new 
cmd[300];
    
    
get_cvar_string("cm_bot_host",ip,charsmax(ip))
    
port get_cvar_num("cm_bot_port")
    
get_cvar_string("cm_bot_user",user,charsmax(user))
    
get_cvar_string("cm_vot_pass",pass,charsmax(pass))
    
    
bothost socket_open(ip,port,SOCKET_TCP,erre)
    
    if ( 
bothost && !erre 
    {
        
server_print("Socket Reopened");
    
        
formatexcmd charsmax(cmd) , "USER asd^r^nPASS asd^r^n" )
        
socket_sendbothost cmd sizeofcmd ) )
    
        
set_task0.5 "socket_read" TASK_RECV+bothost , .flags="b" );
    }
}


public 
socket_readiTaskInfo )
{
    static 
bothost iDataRecv;
    
bothost iTaskInfo TASK_RECV;
    
    if ( 
socket_changebothost ) )
    {
        
iDataRecv socket_recvbothost botcmd charsmaxbotcmd ) );

        
//Not a good way to check if a connection was lost. Better to check when
        //the last response was recvd and if the duration exceeds X seconds, consider
        //connection timed out.
        
if ( !iDataRecv /* equal( botcmd , "" ) */ 
        {
            
server_print("[Network] Connection with Bot has been lost");
            
socket_closebothost );
            
remove_taskiTaskInfo );
            
            
socket_init();
        }
    }



ProIcons 11-25-2010 08:57

Re: [Socket Read]
 
Well thank you for your help, i have done it like yours my self:P also i've changed the task time to 2.50 but every time that it connects to socket from 8 ping i have on localhost:P i am getting a 25 ping... i guess when a player connets from internet and have 45 Ping he will have 65... and it is ... to much..

Bugsy 11-25-2010 09:02

Re: [Socket Read]
 
Better to use a thinking entity instead of set_task, this drastically improved file-transfer time in my FTP include (see code snippets\tuts section).


All times are GMT -4. The time now is 11:25.

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