Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

XML-Socket-Server zur Kommunikation mit Flash

6,644 views

Published on

Vortrag von der International PHP Conference 2002

Published in: Technology
  • If you are looking for customer-oriented academic and research paper writing service try ⇒⇒⇒ WRITE-MY-PAPER.net ⇐⇐⇐ liked them A LOTTT Really nice solutions for the last-day papers
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THE BOOK INTO AVAILABLE FORMAT (New Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download Full doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download PDF EBOOK here { https://urlzs.com/UABbn } ......................................................................................................................... Download EPUB Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... Download doc Ebook here { https://urlzs.com/UABbn } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THE can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THE is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBOOK .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, CookBOOK, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, EBOOK, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THE Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THE the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THE Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download Full EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download Full doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download PDF EBOOK here { https://soo.gd/irt2 } ......................................................................................................................... Download EPUB Ebook here { https://soo.gd/irt2 } ......................................................................................................................... Download doc Ebook here { https://soo.gd/irt2 } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book THIS can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer THIS is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story THIS Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money THIS the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths THIS Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

XML-Socket-Server zur Kommunikation mit Flash

  1. 1. XML Socket Server zur Kommunikation mit Flash International PHP Conference 2002 06/11/2002, Frankfurt-Mörfelden Stephan Schmidt & Gerd Schaufelberger
  2. 2. Inhalt <ul><li>Flash als Client </li></ul><ul><li>Einführung in Sockets </li></ul><ul><li>Socket Funktionen in PHP 4.2 </li></ul><ul><li>Generische Server Klasse &quot;patServer&quot; </li></ul><ul><li>Socket Funktionen in Flash MX </li></ul><ul><li>XML Protokoll zur Kommunikation </li></ul><ul><li>Architektur des XML Servers </li></ul><ul><li>Beispielsapplikation &quot;patTicTacToe&quot; </li></ul>
  3. 3. Gerd Schaufelberger <ul><li>Software Entwickler bei Epygi Labs DE </li></ul><ul><li>Student der Informatik </li></ul><ul><li>Gründungsmitglied der PHP Application Tools http://www.php-tools.net </li></ul><ul><li>Autor von patSysinfo, patUser und anderen Open Source Tools </li></ul>
  4. 4. Stephan Schmidt <ul><li>Web Application Developer bei der Metrix Internet Design GmbH in Karlsruhe </li></ul><ul><li>PHP seit 1999 </li></ul><ul><li>Gründungsmitglied der PHP Application Tools www.php-tools.net </li></ul><ul><li>Autor von patTemplate, patXMLRenderer, patUser und anderen Open Source Klassen </li></ul><ul><li>Regelmäßiger Autor des PHP Magazins </li></ul>
  5. 5. Ist HTML schlecht? <ul><li>Nein, aber... </li></ul><ul><li>entwickelt zur Präsentation von Textinformationen </li></ul><ul><li>Nicht zum Entwickeln von Applikation gedacht </li></ul><ul><li>Ursprünglich nur Links und Formulare zur Interaktion </li></ul><ul><li>verwendet (berechtigterweise) HTTP </li></ul>
  6. 6. Flash vs HTML <ul><li>HTML </li></ul><ul><li>Inkompatibilitäten zwischen verschiedenen Browsern </li></ul><ul><li>Unterschiedliche Darstellung auf verschiedenen Betriebssystemen </li></ul><ul><li>Flash </li></ul><ul><li>Unabhängig von Browser und Betriebssystem, nur Plugin muss installiert sein </li></ul><ul><li>» 1:0 für Flash </li></ul>
  7. 7. Flash vs HTML <ul><li>HTML </li></ul><ul><li>Ursprünglich zur Textaufbereitung entwickelt </li></ul><ul><li>Kaum Multimediafähigkeiten </li></ul><ul><li>Nicht interaktiv </li></ul><ul><li>Flash </li></ul><ul><li>Kombination von Grafik und Text </li></ul><ul><li>Multimediafähig (MP3, Video,...) </li></ul><ul><li>Interaktion möglich </li></ul><ul><li>» 2:0 für Flash </li></ul>
  8. 8. Flash vs HTML <ul><li>HTML </li></ul><ul><li>Übertragung durch HTTP » Verbindungslos » Emulation einer Verbindung durch Sessions </li></ul><ul><li>Flash </li></ul><ul><li>Eingebettet in HTML » Übertragung durch HTTP </li></ul><ul><li>Aber: Flash bietet Möglichkeiten für ständige Serververbindungen </li></ul><ul><li>» 3:0 für Flash </li></ul>
  9. 9. Weitere Vorteile von Flash <ul><li>Einbetten von Schriftarten </li></ul><ul><li>Skalierbare Vektorgrafiken </li></ul><ul><li>Erzeugen von ausführbaren Dateien (Desktop Applikation) </li></ul><ul><li>MP3 Unterstützung </li></ul><ul><li>DOMXML-Support </li></ul><ul><li>Interaktion ohne Request an den Server </li></ul><ul><li>Graphische IDE </li></ul>
  10. 10. Dauerhafte Serververbindung <ul><li>Wichtigstes Feature für diese Session: </li></ul><ul><li>» Ständige Verbindung zum Server durch Sockets </li></ul>
  11. 11. Einführung in Sockets <ul><li>Socket := Endpunkt einer Netzwerkverbindung </li></ul><ul><li>Abstraktionslayer für Netzwerkkommunikation </li></ul><ul><li>Unabhängig von » Programmiersprache » Betriebssystem auf der Gegenstelle </li></ul><ul><li>Endpunkte können auf beliebigen Rechnern liegen </li></ul>
  12. 12. Verbindungslose Sockets <ul><li>Paketorientiert </li></ul><ul><li>Jedes Paket enthält Absender- und Zieladresse </li></ul><ul><li>Verschiedene Pakete können auf unterschiedlichen Wegen zum Ziel gelangen </li></ul><ul><li>Pakete können sich überholen </li></ul><ul><li>Beispiel: UDP (User Datagram Protocol) </li></ul>
  13. 13. Verbindungsorientierte Sockets <ul><li>Verbindungsorientiert </li></ul><ul><li>Verbindungsaufbau am Anfang und Verbindungsabbau am Ende » Overhead </li></ul><ul><li>Route wird beim Verbindungsaufbau festgelegt </li></ul><ul><li>Daten werden ohne weitere Meta-Informationen übertragen » kompensiert Overhead </li></ul><ul><li>Beispiel: TCP </li></ul>
  14. 14. Socket Funktionen in PHP 4.2 <ul><li>Socket Support bereits seit PHP 4.1 </li></ul><ul><li>Bisher instabil und häufigen Änderungen der API unterworfen </li></ul><ul><li>Kompilieren mit --enable-sockets </li></ul><ul><li>Support für Verbindungslose und Verbindungsorientierte Sockets </li></ul><ul><li>nicht fsockopen() </li></ul><ul><li>» Zur Kommunikation mit Flash sind nur </li></ul><ul><li>verbindungsorientierte Sockets interessant. </li></ul>
  15. 15. Erzeugen des Sockets <ul><li>$fd = socket_create( AF_INET, SOCK_STREAM, SOL_TCP ); </li></ul><ul><li>if( $fd ) </li></ul><ul><li>die( &quot;Socket konnte nicht erstellt werden&quot; ); </li></ul><ul><li>Parameter: </li></ul><ul><li>Protokollfamilie (AF_INET) </li></ul><ul><li>Protkolltyp (SOCK_STREAM, SOCK_DGRAM) </li></ul><ul><li>Protokollname (SOL_TCP) </li></ul><ul><li>Rückgabe: </li></ul><ul><li>» File Descriptor </li></ul>
  16. 16. Socket binden und abhören <ul><li>if( !socket_bind( $fd, &quot;myServer.myDomain.net&quot;, 9090 ) </li></ul><ul><li>die( &quot;Konnte Socket nicht an Adresse binden.&quot; ); </li></ul><ul><li>Parameter: </li></ul><ul><li>File Descriptor </li></ul><ul><li>Adresse </li></ul><ul><li>Port </li></ul><ul><li>if( !socket_listen( $fd, 10 ) ) </li></ul><ul><li>die( &quot;Konnte nicht auf Port hören&quot; ); </li></ul><ul><li>Parameter: </li></ul><ul><li>File Descriptor </li></ul><ul><li>Backlog </li></ul>
  17. 17. Verbindungen annehmen <ul><li>$newFd = socket_accept( $fd ); </li></ul><ul><li>Wartet auf eingehende Verbindung </li></ul><ul><li>Skript hält an, bis Verbindung eingeht </li></ul><ul><li>Erzeugt Socket mit identischen Eigenschaften </li></ul><ul><li>Gibt File Descriptor für den erzeugten Socket zurück </li></ul><ul><li>» neuer File Descriptor identifiziert die Verbindung und muss bei weiteren Funktionen verwendet werden. </li></ul>
  18. 18. Daten senden <ul><li>$text = &quot;Hallo Client! &quot;; </li></ul><ul><li>socket_write( $newFd, $text, strlen( $text ) ); </li></ul><ul><li>Länge der Daten muss als dritter Parameter übergeben werden </li></ul><ul><li>Daten kommen automatisch bei der Gegenstelle an </li></ul><ul><li>Gibt false zurück, falls Verbindung abgebrochen ist </li></ul>
  19. 19. Daten empfangen <ul><li>$buf = socket_read( $newFd, 2048 ); </li></ul><ul><li>Parameter: </li></ul><ul><li>File Descriptor </li></ul><ul><li>Anzahl an Bytes, die gelesen werden </li></ul><ul><li>Lesemodus (optional) » Eine Zeile » Binary-safe </li></ul><ul><li>Rückgabe: </li></ul><ul><li>» Gelesene Daten </li></ul>
  20. 20. Talkback Server (Main Loop) <ul><li>while( true ) </li></ul><ul><li>{ </li></ul><ul><li>if( false === ( $buf = socket_read( $newFd, 2048 ) ) ) </li></ul><ul><li>{ </li></ul><ul><li>echo &quot;Fehler beim Lesen.&quot; &quot;; </li></ul><ul><li>break 2; </li></ul><ul><li>} </li></ul><ul><li>if( !$buf = trim( $buf ) ) </li></ul><ul><li>continue; </li></ul><ul><li>if( $buf == '/quit' ) </li></ul><ul><li>break; </li></ul><ul><li>$antwort = &quot;Sie sagten: '$buf'. &quot;; </li></ul><ul><li>socket_write( $newFd, $antwort, strlen( $antwort ) ); </li></ul><ul><li>} </li></ul>
  21. 21. Verbindungen schließen <ul><li>socket_close( $newFd ); </li></ul><ul><li>socket_close( $fd ); </li></ul><ul><li>Verbindungsabbau </li></ul><ul><li>Entfernt den Socket aus dem System </li></ul><ul><li>Gegenstelle registriert Abbau automatisch </li></ul><ul><li>Wichtig: Beide Sockets schließen. </li></ul>
  22. 22. Hinweise <ul><li>Skript läuft in einer Endlosschleife » Zeitlimit beachten </li></ul><ul><li>Nach Möglichkeit CLI Version von PHP verwenden » #!/usr/bin/php -q </li></ul><ul><li>Serverprozess von der Shell abhängen » nohup <Skriptname> & </li></ul>
  23. 23. Keine Kommunikation! <ul><li>Problem: </li></ul><ul><li>Nur ein Client möglich </li></ul><ul><li>Server wird nach Beenden der Verbindung gestoppt </li></ul><ul><li>Lösung: </li></ul><ul><li>Port mit socket_set_opt() wieder freigeben </li></ul><ul><li>socket_select() statt socket_accept() </li></ul><ul><li>Keine Lust alles zu programmieren? » patServer </li></ul>
  24. 24. patServer <ul><li>generische Serverklasse in PHP </li></ul><ul><li>Abstraktion der Socket Funktionalität » Kaum Hintergrundwissen nötig </li></ul><ul><li>Download von http://www.php-tools.net </li></ul><ul><li>Ereignisbasiert » Callback Funktionen werden aufgerufen </li></ul><ul><li>Eigene Serverklasse einfach von patServer ableiten » z.B: HTTP Server, Chat Server,... </li></ul>
  25. 25. Ereignisbehandlung <ul><li>Mögliche Ereignisse und Handler: </li></ul><ul><li>Serverstart » onStart() </li></ul><ul><li>Server wird gestoppt » onShutdown() </li></ul><ul><li>Verbindungsaufbau » onConnect() </li></ul><ul><li>Verbindungsaufbau verweigert » onConnectionRefused() </li></ul><ul><li>Empfang von Daten » onDataReceived() </li></ul><ul><li>Verbindungsabbau » onClose() </li></ul>
  26. 26. Verbindungsmanagement <ul><li>Jeder Client bekommt eine eindeutige ID zugewiesen, wird bei onConnect() übergeben </li></ul><ul><li>Client ID wird bei allen Aktionen des Clients ( onClose() , onConnectionRefused() , onDataReceived() ) an den Handler übergeben </li></ul><ul><li>Methoden zur Interaktion mit den Clients » sendData( $clientId, $data ) » broadcastData( $data ) » closeConnection( $clientId ) » isConnected( $clientId ) </li></ul>
  27. 27. Beispiel <ul><li>class myServer extends patServer </li></ul><ul><li>{ </li></ul><ul><li>function onConnect( $clientId ) </li></ul><ul><li>{ </li></ul><ul><li>echo &quot;Neue Verbindung mit der ID $clientId&quot;; </li></ul><ul><li>} </li></ul><ul><li>function onDataReceived( $clientId, $data ) </li></ul><ul><li>{ </li></ul><ul><li>$this->sendData( $clientId, &quot;Sie haben $data gesendet&quot; ); </li></ul><ul><li>} </li></ul><ul><li>} </li></ul>
  28. 28. Starten des Servers <ul><li>require_once( &quot;include/patServer.php&quot; ); </li></ul><ul><li>require_once( &quot;include/myServer.php&quot; ); </li></ul><ul><li>$server = new myServer( &quot;myServer.myDomain.net&quot;, 9090 ); </li></ul><ul><li>$server->setMaxClients( 50 ); </li></ul><ul><li>$server->start(); </li></ul><ul><li>Hostname und Port werden beim Instanziieren angegeben </li></ul><ul><li>Maximale Anzahl an parallelen Clients kann beschränkt werden </li></ul>
  29. 29. Die andere Seite <ul><li>Flash bietet XMLSocket Objekt </li></ul><ul><li>Stellt verbindungsorientierte Verbindung her </li></ul><ul><li>Daten über diese Verbindung werden im XML Format verschickt » Ausgehende Daten werden serialisiert » Eingehende Daten stehen als DOM-Baum zur Verfügung </li></ul><ul><li>Arbeitet ereignisbasiert </li></ul>
  30. 30. Action Script <ul><li>Erzeugen des XML Sockets: </li></ul><ul><li>var socket = new XMLSocket(); </li></ul><ul><li>socket.connect( &quot;myServer.myDomain.net&quot;, 9090 ); </li></ul><ul><li>Setzen der Ereignishandler: </li></ul><ul><li>socket.onConnect = connectionEstablished; </li></ul><ul><li>socket.onClose = connectionClosed; </li></ul><ul><li>socket.onXML = xmlReceived; </li></ul><ul><li>Methoden zur Ereignisbehandlung müssen noch implementiert werden. </li></ul>
  31. 31. Ereignisbehandlung in Action Script
  32. 32. Senden von Daten <ul><li>var command = new XML(); </li></ul><ul><li>var request = command.createElement(&quot;request&quot;); </li></ul><ul><li>command.appendChild( request ); </li></ul><ul><li>// ...Einfügen weiterer Elemente... </li></ul><ul><li>socket.send( command ); </li></ul><ul><li>Flash stellt DOM Funktionen zur Verfügung </li></ul><ul><li>Daten werden beim Senden serialisiert, z.B. <request><type>pat</type></request> </li></ul>
  33. 33. XML Protokoll <ul><li>Client und Server müssen gemeinsame Sprache sprechen » Protokoll </li></ul><ul><li>&quot;Flaches&quot; XML Format genügt, da keine komplexen Strukturen übetragen werden » Beliebig viele Key/Value Paare </li></ul><ul><li>Protokollprimitiven: » REQUEST » RESPONSE » FAULT </li></ul>
  34. 34. Beispiele <ul><li><request> </li></ul><ul><li><type>Typ der Anfrage</type> </li></ul><ul><li><param>....</param> </li></ul><ul><li><!-beliebig viele Parameter--> </li></ul><ul><li></request> </li></ul><ul><li><response> </li></ul><ul><li><type>Typ der Antwort</type> </li></ul><ul><li><param>....</param> </li></ul><ul><li><!-beliebig viele Parameter--> </li></ul><ul><li></response> </li></ul><ul><li><fault> </li></ul><ul><li><type>Fehlertyp</type> </li></ul><ul><li><param>....</param> </li></ul><ul><li><!-beliebig viele Parameter--> </li></ul><ul><li></fault> </li></ul>
  35. 35. Architektur des Servers <ul><li>patServer Distribution enthält (bald) Basisklasse für XML Server zu Kommunikation mit Flash </li></ul><ul><li>Nachrichten werden automatisch deserialisiert » Neuer Handler: onReceiveRequest() </li></ul><ul><li>Ausgehende Nachrichten werden automatisch serialisiert und mit einem Nullbyte terminiert » Neue Methode: sendResponse() </li></ul><ul><li>Momentan nur mit DOM, bald auch SAX Unterstützung </li></ul>
  36. 36. Schichtenmodell
  37. 37. Beispiel: patTicTacToe
  38. 38. Beispiel: patTicTacToe <ul><li>Beliebig viele Spieler über einen Server </li></ul><ul><li>Für zwei &quot;freie&quot; Spieler wird ein Spiel gestartet </li></ul><ul><li>Komplette Applikationslogik im Server </li></ul><ul><li>Clients übernehmen Präsentationslogik </li></ul><ul><li>Clients nehmen Usereingaben entgegen </li></ul><ul><li>Logik auf Client und Server ist trivial </li></ul>
  39. 39. Protokollausschnitt <ul><li>00:30:36 New connection ( 7 ) from 192.168.1.113 on port 1035 </li></ul><ul><li>00:30:36 Received <request><name>schst</name> <type>signon</type></request> from 7 </li></ul><ul><li>00:30:36 sending: &quot;<response><type>updateScore</type> <score>0</score></response>&quot; to: 7 </li></ul><ul><li>00:30:36 Received <request><type>startGame</type></request> from 7 </li></ul><ul><li>00:30:39 sending: &quot;<response><type>startGame</type> <gameid>3</gameid><item>circle</item> <opponent>argh</opponent></response>&quot; to: 7 </li></ul><ul><li>00:30:39 sending: &quot;<response><type>makeMove</type></response>&quot; to: 7 </li></ul><ul><li>00:35:32 Received <request><xpos>2</xpos><ypos>0</ypos> <type>makeMove</type></request> from 7 </li></ul><ul><li>00:35:32 sending: &quot;<response><type>updateField</type> <xpos>2</xpos><ypos>0</ypos> <item>circle</item></response>&quot; to: 1 </li></ul><ul><li>00:35:32 sending: &quot;<response><type>makeMove</type></response>&quot; to: 1 </li></ul>
  40. 40. Fazit <ul><li>Nahezu unendliche Möglichkeiten » Chats » Virtuelle Welten » Multiplayer-Games » eCommerce Anwenungen » Online-Beratung </li></ul><ul><li>In PHP einfach zu realisieren </li></ul><ul><li>Flash kann HTML in manchen Bereichen ablösen, allerdings nicht überall » Zielgruppe ist wichtig </li></ul>
  41. 41. Ende <ul><li>Viele Dank für Ihre Aufmerksamkeit. </li></ul><ul><li>Weitere Informationen und Folien: </li></ul><ul><li>http://www.php-tools.net </li></ul><ul><li>[email_address] </li></ul><ul><li>[email_address] </li></ul><ul><li>Dank an: </li></ul><ul><li>Sebastian Mordziol, Stephan Eisler, </li></ul><ul><li>Metrix Internet Design GmbH und dem wunderbaren Publikum </li></ul>

×