Visualizzazione dei risultati da 1 a 2 su 2

Discussione: Problema con socket

  1. #1

    Problema con socket

    Dunque, sto creando un IRC bot con PHP usando i socket...sono riuscito a farlo joinare nel canale stabilmente, senza problemi di ping timeout, ma non riesco ancora a fargli riconoscere i messaggi che gli arrivano...come posso fare ?
    vi posto il codice del bot:

    codice:
    <?php
    
    //CONFIGURAZIONE
    $nick = '[TESTBOT2]';
    $server = 'irc.oltreirc.net';
    $chan = '#botphp';
    $port = '6667';
    $realname = 'lol';
    //END CONFIG
    
    $ip = gethostbyname($server);
    $timeout = 60;
    
    // open a socket connection to the IRC server
    $fp = fsockopen($ip, $port, $errno, $errstr, $timeout);
    
    
    if (!$fp) {
        echo $errstr." (".$errno.")
    \n";
    } else {
        // write data through the socket to join the channel
        fwrite($fp, "NICK ".$nick."\r\n");
        fwrite($fp, "USER ".$nick." ".$server." bla :".$realname."\r\n");
        fwrite($fp, "JOIN :".$chan."\r\n");
        
        // write data through the socket to print text to the channel
        fwrite($fp, "PRIVMSG ".$chan." :Hello There!\r\n");
        fwrite($fp, "PRIVMSG ".$chan." :I am a bot\r\n");
        
        // loop through each line to look for ping
         while (!feof($fp)) {
             
            $line =  fgets($fp, 128);
            echo nl2br($line);
            
            $line = explode(" ", $line);
            
            echo $line[0]."\n";
    
            if ($line[0]=="PING") {
                
                fwrite($fp, "PONG ".$line[1]."\r\n"); 
            }
    		
    		if ($line[0]=="!disconnect") {
                
                    fwrite($fp, "PRIVMSG ".$chan." :ByeBye!\r\n");
    				fwrite($fp, "QUIT \r\n");
                    fclose($fp);
            }
    
        }
        
        fclose($fp);
    }
    ?>

  2. #2
    Nessuna sa rispondermi ?

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.