socket connecting error! need help asap

I’m getting this error whenever i try to run my bot:

Heres the script of the connecting

[php] function login() {
$this->loggedIn = false;
if($this->Username==’’||$this->Password==’’) return;//No good login information
$postData = “NameEmail=$this->Username && password=$this->Password && Protected=ON && Locked=ON && Login=Login”;
$res = $this->post_request(‘http://xat.com/web_gear/chat/register.php’, $postData, ‘http://xat.com/web_gear/chat/register.php’);
if($res[‘status’]!=‘ok’) return;//login failed or xat down
$res = $res[‘content’];
$this->regInfo[‘pw’] = $this->getBetween(strtolower($res),strtolower($this->Username)."&pw=",’"’);
if($this->regInfo[‘pw’]==’’) return;
if($this->soc!=null) socket_close($this->soc);
$this->connect(“174.36.242.27”,“10000”);
$this->send(’’);
$this->read();
print_r($this->packet[‘v’]);
$this->regInfo = $this->packet[‘v’];
$this->userID = $this->packet[‘v’][‘i’];
$this->Username = $this->packet[‘v’][‘n’];
if(count($this->regInfo)>4) $this->loggedIn = true;
return true;
}
function run() {

    if($this->login()!=true){
        $this->k = "**BLOCKED**"; 
        $this->userID = "**BLOCKED**";
        $this->loggedIn = false;
    }
    $this->connect("174.36.242.26","10024"); 
    $this->join($this->roomID);
    while($this->read()!="DIED");     
}

function connect($ip, $port) {
    if($this->soc!=null) socket_close($this->soc);
    $this->soc = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
    if(!$this->soc) die(socket_strerror(socket_last_error($this->soc)));
    if(!socket_connect($this->soc,$ip,$port)) die("Could not connect."); 
    
}


function join($roomID) {
    
    $this->send('<y m="1" />');
    $this->read();
    if($this->loggedIn) {
        $p = "";
        $this->regInfo['N'] = $this->regInfo['n'];
        unset($this->regInfo['n']);
        $p .= 'q="1" ';
        $p .= 'y="'.$this->packet['y']['i'].'" ';
        $p .= 'k="'.$this->regInfo['k1'].'" ';
        $p .= 'k3="'.$this->regInfo['k3'].'" ';
        if(isset($this->regInfo['d1'])) $p .= 'd1="'.$this->regInfo['d1'].'" ';
        $p .= 'z="12" p="0" ';
        $p .= 'c="'.$this->roomID.'" ';
        $p .= 'f="0" ';
        $p .= 'u="'.$this->regInfo['i'].'" ';
        $p .= 'm0="671088640" ';
        $p .= 'd0="'.$this->regInfo['d0'].'" ';
        if(isset($this->regInfo['d2'])) $p .= 'd2="'.$this->regInfo['d2'].'" ';
        $p .= 'd3="'.$this->regInfo['d3'].'" ';
        if(isset($this->regInfo['d4'])) $p .= 'd4="'.$this->regInfo['d4'].'" ';
        if(isset($this->regInfo['d5'])) $p .= 'd5="'.$this->regInfo['d5'].'" ';
        if(isset($this->regInfo['d6'])) $p .= 'd6="'.$this->regInfo['d6'].'" ';
        if(isset($this->regInfo['dO'])) $p .= 'dO="'.$this->regInfo['dO'].'" ';
        if(isset($this->regInfo['dx'])) $p .= 'dx="'.$this->regInfo['dx'].'" ';
        $p .= 'dt="'.$this->regInfo['dt'].'" ';
        $p .= 'N="'.$this->Username.'" ';
        $p .= 'n="'.$this->name.'" ';
        $p .= 'a="'.$this->avatar.'" ';
        $p .= 'h=".$this->homepage." ';
        $p .= 'v="0" ';
        $p = trim($p);
        $this->send('<j2 '.$p.' />');
    $this->sendMessage('DuBot has arrived!');
    } else {
        
        $this->send('<j2 q="1" y="'.$this->packet['y']['i'].'" k="'.$this->k.'" k3="0" z="12" p="0" c="'.$roomID.'" f="0" u="'.$this->userID.'" d0="0" n="'.$this->name.'" a="'.$this->avatar.'" h="'.$this->homepage.'" v="0" />');
    }
}

/**
 * Writes the given message to the object socket($this->soc)
 * @param $message The packet to send.
 */
function send($message) {
    
    if($this->debug)echo "->>\t $message\n";
    socket_write($this->soc, $message."\0", strlen($message)+1); 
}

/**
 * Reads a message from the socket, will read until entire message has been recieved or connection closes.
 * @param $parse Used for recursive calls to tell the function not to parse a partial packet
 */
function read($parse=true) {
    $res = rtrim(socket_read($this->soc, 4096));
    
    if($this->debug)echo "<<-\t $res\n";
    if(!$res) {
        return "DIED"; //Used to gracefully handle a closed socket
        echo $res." then DIED\n";
    }
    $this->lastPacket = $res;
    if($res{strlen($res)-1}!='>') { $res.=$this->read(false);} //Recursive call for messages split over several packets.
    if($parse)$this->parse($res);
    return $res;
}

/**
 * Performs a basic HTTP GET to the given URL
 * @param $url The url to retrieve, please include http:// and www if necessary
 * @param $includeHeader Tells teh function wether or not to include the server header respond before the main content
 */
function get($url, $includeHeader=false) {
    $urlp = parse_url($url); 
    $fp = fsockopen($urlp['host'],80); 
    $path = explode('/',$url,4);
    $path = ((count($path)>=4)?$path[3]:"");
    $req = "GET /$path HTTP/1.1\r\n";
    $req .= "Host: $urlp[host]\r\n";
    $req .= "Connection: Close\r\n\r\n";
    fputs($fp, $req);
    $res = ""; 
    while(!feof($fp)) $res .= fgets($fp, 4096);
    fclose($fp);
    if($includeHeader) return $res;
    $res = explode("\r\n\r\n",$res,2);
    return $res[1];
}
 
function post_request($url, $data, $referer='') {
 $url = parse_url($url);
        $host = $url['host'];
        $path = $url['path'];
        $fp = fsockopen($host, 80, $errno, $errstr, 30);
        if ($fp){
            fputs($fp, "POST $path HTTP/1.1\r\n");
            fputs($fp, "Host: $host\r\n");
            if ($referer != '')
                fputs($fp, "Referer: $referer\r\n");
            fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n");
            fputs($fp, "Content-length: ". strlen($data) ."\r\n");
            fputs($fp, "Connection: close\r\n\r\n");
            fputs($fp, $data);
            $res = ''; 
            while(!feof($fp)) {
                
                $res .= fgets($fp, 128);
            }
        }
        else { 
            return array(
                'status' => 'err', 
                'error' => "$errstr ($errno)"
            );
        }
        fclose($fp);
        $res = explode("\r\n\r\n", $res, 2);
        $header = isset($res[0]) ? $res[0] : '';
        $content = isset($res[1]) ? $res[1] : '';
        return array(
            'status' => 'ok',
            'header' => $header,
            'content' => $content
        );
}

/**
 * Parses the recieved packets into their message and types.
 * @param $packet The packet recieved.
 */
function parse($packet) {
    if(substr_count($packet,'>')>1) $packet = explode('/>',$packet);//If necessary split the packet into individual messages
    foreach((Array)$packet as $p) {
        $p = trim($p);
        if(strlen($p)<5) return;//garbage data
        $type = trim(strtolower(substr($p,1,strpos($p.' ',' '))));//packet type
        $p = trim(str_replace("<$type",'',str_replace('/>','',$p)));//remove details so it is just the info to be parsed
        parse_str(str_replace('"','',str_replace('" ','&',str_replace('="','=',str_replace('&','__38',$p)))),$this->packet[$type]);
        foreach($this->packet[$type] as $k=>$v) {
            $this->packet[$type][$k] = str_replace('__38','&',$v); //htmlspecial chars are protected instead of being parsed 
        }
        $this->handle($type,$p);
    }
}

/**
 * This is the inital handler for the packets, parses them and sends them off to their respective function to be handled further.
 * @param $type The character code indicating the type of data within the message.
 * @param $message The data the message contains.
 */
function handle($type,$msg) { 
    switch($type) {
        case 'gp':
            if(isset($this->packet['gp']['x']))
            $this->send('<x i="'.$this->packet['gp']['x'].'" u="'.$this->userID.'" t="j" />'); //Handle groups
        break;
        case 'q'://XAT notice to change ip/port
            $this->connect($this->packet['q']['d'], $this->packet['q']['p']);
            $this->join($this->roomID);
        break;  
        case 'o': 
            $this->packet['o']['u'] = $this->parseU(@$this->packet['u']['u']);
            $this->userInfo[$this->packet['o']['u']]['name'] = @$this->packet['o']['n'];
            $this->userInfo[$this->packet['o']['u']]['registeredName'] = ((isset($this->packet['o']['N']))?$this->packet['o']['N']:'');
            $this->userInfo[$this->packet['o']['u']]['avatar'] = @$this->packet['o']['a'];
            $this->userInfo[$this->packet['o']['u']]['homepage'] = @$this->packet['o']['h'];
            $this->userInfo[$this->packet['o']['u']]['rank'] = $this->f2rank(@$this->packet['o']['f']);
        break;
        case 'u':
            //Joined
            //Default Bot stuff regarding userInformation
            $this->packet['u']['u'] = $this->parseU(@$this->packet['u']['u']);
            $this->userInfo[$this->packet['u']['u']]['name'] = @$this->packet['u']['n'];
            $this->userInfo[$this->packet['u']['u']]['registeredName'] = ((isset($this->packet['u']['N']))?$this->packet['u']['N']:'');
            $this->userInfo[$this->packet['u']['u']]['avatar'] = @$this->packet['u']['a'];
            $this->userInfo[$this->packet['u']['u']]['homepage'] = @$this->packet['u']['h'];
            $this->userInfo[$this->packet['u']['u']]['rank'] = $this->f2rank(@$this->packet['u']['f']);
            
            $event = 'userJoined';
            $data['id'] = $this->packet['u']['u'];
            $data['old'] = ($type=='o'||(isset($this->packet['u']['s']))?true:false);
            $this->handleEvent($event,$data);
            
        break;
        case 'l':
            //User Left or was kicked, banned
            unset($this->userInfo[$this->packet['l']['u']]);
            $event = 'userLeft';
            $data['id'] = $this->packet['l']['u'];
            $this->handleEvent($event,$data);
            
        break;
        case 'p':
            //Private message/chat recieved
            $event = ((isset($this->packet['p']['d']))?'privateChat':'privateMessage');
            $data['id'] =  $this->parseU(@$this->packet['p']['u']);
            $data['message'] = $this->packet['p']['t'];
            $this->handleEvent($event,$data);
        break;
        case 'm':
            //message to main chat.
            $event = 'message';
            $data['id'] = $this->parseU(@$this->packet['m']['u']);
            $data['message'] = $this->packet['m']['t'];
            $data['old'] = ((isset($this->packet['m']['s']))?true:false);
            $this->handleEvent($event,$data);
        break;
    }
}
[/php]

Line 622: (socket_write)
[php]function send($message) {

    if($this->debug)echo "->>\t $message\n";
    socket_write($this->soc, $message."\0", strlen($message)+1); 
}[/php]

line 630: ($res = rtim…)
[php]function read($parse=true) {
$res = rtrim(socket_read($this->soc, 4096));

    if($this->debug)echo "<<-\t $res\n";
    if(!$res) {
        return "DIED"; //Used to gracefully handle a closed socket
        echo $res." then DIED\n";
    }
    $this->lastPacket = $res;
    if($res{strlen($res)-1}!='>') { $res.=$this->read(false);} //Recursive call for messages split over several packets.
    if($parse)$this->parse($res);
    return $res;
}[/php]

I’m not sure whats wrong here -_-
I am clueless when it comes to php and packets so I’m hoping someone here can help!

bump. i seriously need help with this. i cant find the answer anywhere and no one will help me so i came here for it but apparently the php experts here are too busy to help

Sponsor our Newsletter | Privacy Policy | Terms of Service