php.de

Zurück   php.de > Webentwicklung > PHP-Fortgeschrittene

PHP-Fortgeschrittene Arbeiten mit PHP ohne Einschränkungen

Antwort
 
LinkBack Themen-Optionen Thema bewerten
Alt 06.07.2008, 17:03  
Erfahrener Benutzer
 
Registriert seit: 07.06.2008
Beiträge: 992
PHP-Kenntnisse:
Fortgeschritten
Frank befindet sich auf einem aufstrebenden Ast
Frank eine Nachricht über ICQ schicken Frank eine Nachricht über MSN schicken Frank eine Nachricht über Yahoo! schicken
Standard Probleme mit socket_send()

Hi, ich bastel grad an einem Admin tool für ein Game.
Die Kommunikation mit dem Server des Spiels erfolgt über eine XML-RPC Schnittstelle. Mein Problem ist nun, dass ich zwar mit socket_rescv daten vom server empfange (nämlich den Handshake), danach aber nichts mit socket_send senden kann.

PHP sagt zwar immer
Zitat:
Errorno: 0
Error: Der Vorgang wurde erfolgreich abgeschlossen.
aber es kommt nichts an.
Ich habe bereits alle anderen Möglichkeiten ausgeschlossen. Es muss am PHP liegen.
Setze ich das ganze statt mit sockets über die stream-funktionen um, so funktioniert es tadellos.

Vielleicht könnt ihr ja den Fehler finden, ich suche nämlich schon seit 2 Stunden mit einem Freund und finde da nicht, warum das Gesendete nicht ankommt

PHP-Code:
<?php
interface iServer {
    public function 
__construct();
    public function 
__destruct();
}
class 
Server extends Protocol implements iServer {
    private 
$logbook;
    private 
$socket;
    private 
$domain;
    private 
$type;
    private 
$protocol;
    private 
$lasterror;
    private 
$strerror;
    private 
$address;
    private 
$port;
    private 
$connection;
    public function 
__construct() {
        global 
$kernel;
        
Protocol::__construct();
        
$this->logbook $kernel->load("Logbook");
        
$this->domain AF_INET;
        
$this->type SOCK_STREAM;
        
$this->protocol SOL_TCP;
        
$this->address "localhost";
        
$this->port 5000;
        
$this->connection null;
        
$this->_getConfig();
    }
    public function 
connect() {
        
$this->socket = @socket_create($this->domain$this->type$this->protocol);
        if(
$this->socket === false) {
            
$this->_getErrors();
            
$this->logbook->log("se""Could not create socket @ ".$this->lasterror.":".$this->strerror."!");
        }
        
$this->logbook->log("s""Successfully created socket!");
        
$this->connection = @socket_connect($this->socket$this->address$this->port);
        if(
$this->connection === false) {
            
$this->_getErrors();
            
$this->logbook->log("se""Could not connect socket to ".$this->address.":".$this->port." @ ".$this->lasterror.":".$this->strerror."!");
        }
        
$this->logbook->log("s""Successfully connected socket to ".$this->address.":".$this->port."!");
        
$this->_handshake();
        
################################################################################################        
        
socket_send($this->socket"blabla"6null);
        
$this->_getErrors();
        echo 
$this->lasterror;
        echo 
$this->strerror;
################################################################################################
    
}
    private function 
_getConfig() {
        
$config parse_ini_file(getcwd().DIRECTORY_SEPARATOR."config".DIRECTORY_SEPARATOR."server.ini");
        foreach(
$config as $setting=>$value) {
            
$this->$setting $value;
        }
    }
    private function 
_getErrors() {
        
$this->lasterror socket_last_error($this->socket);
        
$this->strerror socket_strerror($this->lasterror);
    }
    private function 
_handshake() {
        if(!@
socket_recv($this->socket$length4null)) {
            
$this->_getErrors();
            
$this->logbook->log("s""Receiving from socket failed @ ".$this->lasterror.":".$this->strerror."!");
        }
        
$length = @ord($length);
        if(!@
socket_recv($this->socket$handshake$lengthnull)) {
            
$this->_getErrors();
            
$this->logbook->log("s""Receiving from socket failed @ ".$this->lasterror.":".$this->strerror."!");
        }
        if(
$handshake !== "GBXRemote 2") {
            
$this->logbook->log("se""Handshake failed! Obviously connected to wrong server!");
        }
        
$this->logbook->log("s""Handshake succeeded! Connected to Trackmania Server!");
    }
    public function 
__destruct() {
        
Protocol::__destruct();
        
socket_close($this->socket);
        unset(
$this);
    }
}
?>
Ich habe euch die entsprechende Stelle mit # markiert. (Diese Stelle ist da nur zum testen drin, hat also keine wirkliche Funktion, macht aber das Problem deutlich)

Falls jemand noch die Klasse Protocol sehen möchte (wegen extend) hier ist sie. Hier kann der Fehler jedoch NICHT liegen.

PHP-Code:
<?php
interface iProtocol {
    public function 
__construct();
    public function 
p_method();
    public function 
__destruct();
}
class 
Protocol implements iProtocol {
    private 
$xml;
    public function 
__construct() {
        
$this->xml "";
    }
    public function 
p_method() {
        
$arguments func_get_args();
        
$method array_shift($arguments);
        
$this->xml "<?xml version='1.0' encoding='UTF-8' ?>";
        
$this->xml .= "<methodCall>";
        
$this->xml .= "<methodName>";
        
$this->xml .= $method;
        
$this->xml .= "</methodName>";
        
$this->xml .= "<params>";
        foreach(
$arguments as $argument) {
            
$this->xml .= "<param>";
            
$this->xml .= "<value>";
            
$this->xml .= $this->_input($argument);
            
$this->xml .= "</value>";
            
$this->xml .= "</param>";
        }
        
$this->xml .= "</params>";
        
$this->xml .= "</methodCall>";
        return 
$this->xml;
    }
    private function 
_input($argument) {
        
$type $this->_getType($argument);
        if(
$type == "boolean") {
            return 
"<boolean>".(int)$argument."</boolean>";
        }
        if(
$type == "integer") {
            return 
"<int>".$argument."</int>";
        }
        if(
$type == "double") {
            return 
"<double>".$argument."</double>";
        }
        if(
$type == "string") {
            return 
"<string>".htmlspecialchars($argument)."</string>";
        }
        if(
$type == "array") {
            
$return "<array><data>";
            foreach(
$argument as $element) {
                
$return .= "<value>".$this->_input($element)."</value>";
            }
            
$return .= "</data></array>";
            return 
$return;
        }
        
$return "<struct>";
        foreach(
$argument as $key=>$element) {
            
$return .= "<member>";
            
$return .= "<name>".$key."</name>";
            
$return .= "<value>".$this->_input($element)."</value>";
            
$return .= "</member>";
        }
        
$return .= "</struct>";
        return 
$return;
    }
    private function 
_getType($argument) {
        switch(
gettype($argument)) {
            case 
"boolean":
                return 
"boolean";
            break;
            case 
"integer":
                return 
"integer";
            break;
            case 
"double":
                return 
"double";
            break;
            case 
"string":
                return 
"string";
            break;
            case 
"array":
                
$struct false;
                foreach(
$argument as $key=>$value) {
                    if(
is_int($key)) {
                        continue;
                    }
                    
$struct true;
                    break;
                }
                if(
$struct) {
                    return 
"struct";
                }
                return 
"array";
            break;
        }
    }
    public function 
__destruct() {
        unset(
$this);
    }
}
?>
__________________
Frank ist offline   Mit Zitat antworten
Sponsor Mitteilung
PHP Code Flüsterer

Registriert seit: 21.08.2005
Beiträge: 4682
PHP-Kenntnisse:
Fortgeschritten

Antwort


Themen-Optionen
Thema bewerten
Thema bewerten:

Forumregeln
Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are an
Gehe zu

Ähnliche Themen
Thema Autor Forum Antworten Letzter Beitrag
[Erledigt] Firefox / IE - Probleme HTML, Usability und Barrierefreiheit 5 20.07.2009 17:04
Probleme bei Speicherung von serialize() Strings Manni2k PHP Tipps 2006 13 15.10.2006 15:06
Probleme mit mbstring extension unter Debian HStev Server, Hosting und Workstations 3 30.08.2006 20:55
Probleme mit Rechteverteilung chmod() per script!!!??? Funky_ PHP Tipps 2006 7 17.06.2006 17:10
[Erledigt] Probleme beim Mailserver Postfix mit Umlauten Server, Hosting und Workstations 5 15.02.2006 21:55
Probleme bei der Installation von Turck MMCache tomx992 PHP-Fortgeschrittene 2 27.09.2005 20:31
Probleme beim Datenupload zu meiner Datenbank Datenbanken 3 05.09.2005 19:47
Probleme mit Sonderzeichen... Datenbanken 1 02.08.2005 23:37
[Erledigt] hilfe! probleme mit... PHP Tipps 2005 4 12.04.2005 22:55
[Erledigt] CSV Größe macht Probleme mit php PHP Tipps 2005 5 15.03.2005 21:29
Performances Probleme bei z.B. LIMIT 300000,10 Datenbanken 28 13.02.2005 10:57
Zwei Rechner ins Netz - Router - Hub - Probleme... imported_Ben Off-Topic Diskussionen 37 13.01.2005 21:36
[Erledigt] Technische Probleme mit Sessions PHP-Fortgeschrittene 4 18.11.2004 14:45
[Erledigt] Probleme mit Fremdsprachen HTML, Usability und Barrierefreiheit 2 21.09.2004 17:11
PHP Bilder in DB / Probleme bei Änderung PHP-Fortgeschrittene 1 05.06.2004 11:20

Besucher kamen über folgende Suchanfragen bei Google auf diese Seite
php socket_send, socket_send php, socket_send() php, php socket_recv string encode utf, socket_send, trackmania server socket, php socket_send typ, xmlrpc php trackmania tutorial, trackmania server echo xmlrpc, gbxremote protocol, gbxremote problem debian

Alle Zeitangaben in WEZ +2. Es ist jetzt 20:25 Uhr.




Powered by vBulletin® Version 3.7.2 (Deutsch)
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
Aprilia-Forum, Aquaristik-Forum, Liebeskummer-Forum, Zierfisch-Forum, Geizkragen-Forum