<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>lemmingzshadow.net &#187; Websockets - lemmingzshadow.net - a webdevel&#039;s weblog</title>
	<atom:link href="http://lemmingzshadow.net/tag/websockets/feed/" rel="self" type="application/rss+xml" />
	<link>http://lemmingzshadow.net</link>
	<description>a webdevel&#039;s weblog</description>
	<lastBuildDate>Fri, 27 Jan 2012 20:18:19 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>PHP Websocket Server/Client nach Draft hybi-10</title>
		<link>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/</link>
		<comments>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/#comments</comments>
		<pubDate>Tue, 20 Sep 2011 12:16:26 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[featured post]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=386</guid>
		<description><![CDATA[Vor ein paar Tagen habe ich ja schon einen Websocket-Client hier veröffentlich, welcher Draft hybi-00 unterstützt. Kurz danach veröffentlichte google jedoch eine neue Version von Chrome. In Chrome 14 hat google nun den Websocket-Draft hybi-10 implementiert und dort hat sich vieles grundlegend geändert. Neben einem neuen Handshake werden auch die Datenframes komplett neu codiert. Ich [...]]]></description>
			<content:encoded><![CDATA[<p>Vor ein paar Tagen habe ich ja schon einen Websocket-Client hier veröffentlich, welcher Draft hybi-00 unterstützt. Kurz danach veröffentlichte google jedoch eine neue Version von Chrome. In Chrome 14 hat google nun den <a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-10">Websocket-Draft hybi-10</a> implementiert und dort hat sich vieles grundlegend geändert. Neben einem neuen Handshake werden auch die Datenframes komplett neu codiert.<br />
Ich habe meine Client-Klasse entsprechend angepasst und möchte sie natürlich wieder hier präsentieren, da sie dem ein oder anderen Entwickler sicherlich helfen wird. Desweiteren habe ich die &#8220;Connection-Klasse&#8221; des Websocket-Servers von Nico Kaiser so angepasst, dass sie auch den hybi10-Draft unterstützt.</p>
<p>Viel Spass bei basteln <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><strong style="text-decoration: underline;">HINWEIS:</strong> Da der Server aktuell ständig weiterentwickelt wird habe ich ein Repository auf Github angelegt. Bitte den jeweils aktuelle Code verwenden: <a href="https://github.com/lemmingzshadow/php-websocket">https://github.com/lemmingzshadow/php-websocket</a></p>
<p><strong style="text-decoration: underline;">UPDATE:</strong> As the project is constantly updated and improved I created a repository on github. Please get the code here: <a href="https://github.com/lemmingzshadow/php-websocket">https://github.com/lemmingzshadow/php-websocket</a></p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/feed/</wfw:commentRss>
		<slash:comments>36</slash:comments>
		</item>
		<item>
		<title>PHP Websocket Client</title>
		<link>http://lemmingzshadow.net/379/php-websocket-client/</link>
		<comments>http://lemmingzshadow.net/379/php-websocket-client/#comments</comments>
		<pubDate>Thu, 15 Sep 2011 13:43:22 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=379</guid>
		<description><![CDATA[Seit einiger Zeit spiele ich immer mal wieder mit Websockets. Allerdings habe ich bisher keinen wirklich funktionstüchtigen, in PHP implementierten Websocket-Client finden können. Also habe ich kurzerhand selbst eine Klasse dafür gebaut welche ich hier natürlich gerne veröffentliche. Absolut minimal, aber für Testzwecke ausreichend. Es wird aktuell der Handshake aus Draft &#8220;draft-ietf-hybi-thewebsocketprotocol-00&#8221; unterstürzt. Getestet habe [...]]]></description>
			<content:encoded><![CDATA[<p>Seit einiger Zeit spiele ich immer mal wieder mit <a href="http://lemmingzshadow.net/tag/websockets/">Websockets</a>. Allerdings habe ich bisher keinen wirklich funktionstüchtigen, in PHP implementierten Websocket-Client finden können. Also habe ich kurzerhand selbst eine Klasse dafür gebaut welche ich hier natürlich gerne veröffentliche. Absolut minimal, aber für Testzwecke ausreichend. Es wird aktuell der Handshake aus Draft &#8220;<a href="http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-00">draft-ietf-hybi-thewebsocketprotocol-00</a>&#8221; unterstürzt. Getestet habe ich es mit der aktuellen Version von Chrome (13.0.782) und dem <a href="https://github.com/nicokaiser/php-websocket">Websocket Server von Nico Kaiser</a>.</p>
<p>Hier die Klasse + Beispielaufruf:</p>
<p><strong>ACHTUNG:</strong> Eine aktuellere Version dieser Klasse gibt es hier: <a href="http://lemmingzshadow.net/386/php-websocket-serverclient-nach-draft-hybi-10/">PHP Websocket Server/Client nach Draft hybi-10</a></p>
<p><span id="more-379"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #009933; font-style: italic;">/**
 * Very basic websocket client.
 * Supporting handshake from drafts:
 *	draft-hixie-thewebsocketprotocol-76
 *	draft-ietf-hybi-thewebsocketprotocol-00
 * 
 * @author Simon Samtleben &lt;web@lemmingzshadow.net&gt;
 * @version 2011-09-15
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> WebsocketClient
<span style="color: #009900;">&#123;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$_Socket</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>	
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> __destruct<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> sendData<span style="color: #009900;">&#40;</span><span style="color: #000088;">$data</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #666666; font-style: italic;">// send actual data:</span>
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x00</span>&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$data</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\xff</span>&quot;</span> <span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error:'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errno</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errstr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$wsData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$retData</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$wsData</span><span style="color: #339933;">,</span><span style="color: #0000ff;">&quot;<span style="color: #660099; font-weight: bold;">\x00</span><span style="color: #660099; font-weight: bold;">\xff</span>&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>        
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$retData</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _connect<span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$key1</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$key2</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">32</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$key3</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">8</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">,</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>		
&nbsp;
		<span style="color: #000088;">$header</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;GET /echo HTTP/1.1<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Upgrade: WebSocket<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Connection: Upgrade<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Host: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$host</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;:&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$port</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Origin: http://foobar.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Sec-WebSocket-Key1: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key1</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Sec-WebSocket-Key2: &quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$key2</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$header</span><span style="color: #339933;">.=</span> <span style="color: #000088;">$key3</span><span style="color: #339933;">;</span>
&nbsp;
&nbsp;
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket <span style="color: #339933;">=</span> <span style="color: #990000;">fsockopen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$host</span><span style="color: #339933;">,</span> <span style="color: #000088;">$port</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errno</span><span style="color: #339933;">,</span> <span style="color: #000088;">$errstr</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">2</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #990000;">fwrite</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #000088;">$header</span><span style="color: #009900;">&#41;</span> or <span style="color: #990000;">die</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Error: '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errno</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">':'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$errstr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
		<span style="color: #000088;">$response</span> <span style="color: #339933;">=</span> <span style="color: #990000;">fread</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #339933;">,</span> <span style="color: #cc66cc;">2000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #009933; font-style: italic;">/**
		 * @todo: check response here. Currently not implemented cause &quot;2 key handshake&quot; is already deprecated.
		 * See: http://en.wikipedia.org/wiki/WebSocket#WebSocket_Protocol_Handshake
		 */</span>		
&nbsp;
		<span style="color: #b1b100;">return</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _disconnect<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>
		<span style="color: #990000;">fclose</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span>_Socket<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> _generateRandomString<span style="color: #009900;">&#40;</span><span style="color: #000088;">$length</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #000088;">$addSpaces</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #000088;">$addNumbers</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
	<span style="color: #009900;">&#123;</span>  
		<span style="color: #000088;">$characters</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ!&quot;§$%&amp;/()=[]{}'</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$useChars</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #666666; font-style: italic;">// select some random chars:    </span>
		<span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$i</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span> <span style="color: #339933;">&lt;</span> <span style="color: #000088;">$length</span><span style="color: #339933;">;</span> <span style="color: #000088;">$i</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$useChars</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$characters</span><span style="color: #009900;">&#91;</span><span style="color: #990000;">mt_rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #990000;">strlen</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$characters</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #666666; font-style: italic;">// add spaces and numbers:</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$addSpaces</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">' '</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$addNumbers</span> <span style="color: #339933;">===</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span>
		<span style="color: #009900;">&#123;</span>
			<span style="color: #990000;">array_push</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span><span style="color: #cc66cc;">9</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #009900;">&#125;</span>
		<span style="color: #990000;">shuffle</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$useChars</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">trim</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">implode</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">''</span><span style="color: #339933;">,</span> <span style="color: #000088;">$useChars</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomString</span> <span style="color: #339933;">=</span> <span style="color: #990000;">substr</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$randomString</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #000088;">$length</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #000088;">$randomString</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000088;">$WebSocketClient</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> WebsocketClient<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'127.0.0.1'</span><span style="color: #339933;">,</span> <span style="color: #cc66cc;">8000</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$WebSocketClient</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendData</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'1337'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$WebSocketClient</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/379/php-websocket-client/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Ajax Push Engine APE reanimiert JiTT</title>
		<link>http://lemmingzshadow.net/279/ajax-push-engine-ape-reanimiert-jitt/</link>
		<comments>http://lemmingzshadow.net/279/ajax-push-engine-ape-reanimiert-jitt/#comments</comments>
		<pubDate>Sun, 07 Mar 2010 18:06:16 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[APE]]></category>
		<category><![CDATA[Websockets]]></category>
		<category><![CDATA[Webtechnik]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=279</guid>
		<description><![CDATA[Vor einiger Zeit habe ich ein kleines Bastelprojekt mit den Namen JiTT ins Leben gerufen um das Kaazing Gateway zu testen. Leider gibt es am Kaazing Gateway schon seit einiger Zeit keine Aktualisierungen mehr und mich habe mich nach Alternativen umgeschaut. Gefunden habe ich die Ajax Push Engine kurz APE. Genau wie das Kaazing Gateway [...]]]></description>
			<content:encoded><![CDATA[<p>Vor einiger Zeit habe ich ein kleines <a href="http://lemmingzshadow.net/163/jittcc-erste-gehversuche-mit-websockets/">Bastelprojekt</a> mit den Namen <a href="http://jitt.geekservice.de">JiTT</a> ins Leben gerufen um das <a href="http://www.kaazing.org/confluence/display/KAAZING/Home">Kaazing Gateway</a> zu testen. Leider gibt es am Kaazing Gateway schon seit einiger Zeit keine Aktualisierungen mehr und mich habe mich nach Alternativen umgeschaut. Gefunden habe ich die <a href="http://www.ape-project.org/">Ajax Push Engine</a> kurz APE.<br />
Genau wie das Kaazing Gateway bietet APE die Möglichkeit persistente Verbindungen zwischen Client (Browser) und Server aufzubauen. Dabei wird ein Coment-Server und ein kleines Javascript Framework benutzt.<br />
Die Installation ist Dank eines deb-Paketes sehr einfach und gut dokumentiert. Weiterhin gibt es einige Demo-Anwendungen so dass man schnell anfangen kann zu basteln.<br />
Ein Vorteil gegenüber dem Kaazing-Gateway: APE benötigt keine Java-Laufzeitumgebung und kommt somit mit wesentlich weniger Arbeitsspeicher aus. Insgesamt wirkt der Comet-Server um einiges schlaker und performanter. Lasttests konnte ich bisher noch nicht machen, ich werde mich aber bemühen dies nachzuholen.</p>
<p>Abschließend noch der Hinweis, dass das Projekt JiTT ab sofort und folgender URL zu finden ist: <a href="http://jitt.geekservice.de"><strong>http://jitt.geekservice.de</strong></a></p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/279/ajax-push-engine-ape-reanimiert-jitt/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>jitt.cc &#8211; neue Funktion: Twitter Walls</title>
		<link>http://lemmingzshadow.net/166/jittcc-neue-funktion-twitter-walls/</link>
		<comments>http://lemmingzshadow.net/166/jittcc-neue-funktion-twitter-walls/#comments</comments>
		<pubDate>Sun, 10 May 2009 17:45:45 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[jitt.cc]]></category>
		<category><![CDATA[PHPIDS]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=166</guid>
		<description><![CDATA[Soeben habe ich das erste Update an meinem Websocket-Projekt jitt.cc live geschaltet. Ab sofort können neben der Public Timeline von twitter auch Walls &#8220;live&#8221; angeschaut werden. In Twitter-Walls werden nur Tweets gelistet welche einen bestimmten Suchbegriff enthalten. Neue Tweets erscheinen auch hier direkt ohne das der Client einen Reload o.Ä. machen muss. (Beispiel: http://jitt.cc/wall/simpsons/) Ansonsten [...]]]></description>
			<content:encoded><![CDATA[<p>Soeben habe ich das erste Update an meinem Websocket-Projekt <a href="http://jitt.cc">jitt.cc</a> live geschaltet. Ab sofort können neben der Public Timeline von twitter auch Walls &#8220;live&#8221; angeschaut werden. In Twitter-Walls werden nur Tweets gelistet welche einen bestimmten Suchbegriff enthalten. Neue Tweets erscheinen auch hier direkt ohne das der Client einen Reload o.Ä. machen muss. (Beispiel: <a href="http://jitt.cc/wall/simpsons/">http://jitt.cc/wall/simpsons/</a>)<br />
<span id="more-166"></span><br />
Ansonsten gab es noch ein paar interne Änderungen von denen man (hoffentlich) als Besucher nichts mitbekommt. Unter anderem habe ich die aktuelle Version von <a href="http://php-ids.org/">PHPIDS</a> integriert. Hier lasse ich ein Cache und die Logs in die Datenbank schreiben um zu sehen ob man so die Performance von PHPIDS noch etwas steigern kann. Natürlich macht sich das erst bemerkbar wenn das Projekt etwas an Fahrt aufgenommen hat. Ich werde dann darüber berichten.</p>
<p>Zum Schluss noch einmal der Hinweis: jitt.cc ist nach wie vor ein Testprojekt und es kann durchaus vorkommen, dass mal etwas nicht richtig funktioniert <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/166/jittcc-neue-funktion-twitter-walls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>jitt.cc &#8211; Erste Gehversuche mit Websockets</title>
		<link>http://lemmingzshadow.net/163/jittcc-erste-gehversuche-mit-websockets/</link>
		<comments>http://lemmingzshadow.net/163/jittcc-erste-gehversuche-mit-websockets/#comments</comments>
		<pubDate>Mon, 04 May 2009 17:58:07 +0000</pubDate>
		<dc:creator>Lemmingz Shadow</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[ActiveMQ]]></category>
		<category><![CDATA[Kaazing]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[STOMP]]></category>
		<category><![CDATA[Websockets]]></category>

		<guid isPermaLink="false">http://lemmingzshadow.net/?p=163</guid>
		<description><![CDATA[Am Wochenende habe ich ein erstes kleines neues Projekt zusammen gebastelt um ein wenig mit Websocketes zu experimentieren. jitt.cc macht momentan nicht viel mehr als die Twitter Public Timeline &#8220;live&#8221; im Browser anzuzeigen. Natürlich ist mir bekannt, dass es schon viele Projekte gibt die genau diese Funktion bereits bieten. Mir geht es aber weniger um [...]]]></description>
			<content:encoded><![CDATA[<p>Am Wochenende habe ich ein erstes kleines neues Projekt zusammen gebastelt um ein wenig mit Websocketes zu experimentieren. <a href="http://jitt.cc"><strong>jitt.cc</strong></a> macht momentan nicht viel mehr als die Twitter Public Timeline &#8220;live&#8221; im Browser anzuzeigen. Natürlich ist mir bekannt, dass es schon viele Projekte gibt die genau diese Funktion bereits bieten. Mir geht es aber weniger um die Funktion sondern um die eingesetzte Technik.<span id="more-163"></span><br />
Die meisten Live-Twitter Seiten verwenden irgendeine Art des Pollings um den Live-Effekt zu erzeugen, bei jitt.cc hingegen werden die Daten über eine persistente Verbindung direkt vom Server an den Client geschickt. Hierzu setze ich das <a href="http://www.kaazing.org">Kaazing Open Gateway</a> und einen <a href="http://activemq.apache.org/">ActiveMQ</a> Server ein.<br />
Kaazing stellt quasi eine Proxy zwischen dem ActiveMQ Server und dem Brower dar. Wie das genau funktioniert ist <a href="http://www.kaazing.org/confluence/display/Doc/Architecture+Overview#kegcomps">hier</a> sehr schön dargestellt.<br />
Die Textnachrichten werden dann mittels <a href="http://en.wikipedia.org/wiki/Streaming_Text_Orientated_Messaging_Protocol">STOMP</a> vom ActiveMQ Server über eine Websocket-Verbindung an den Client gesendet.</p>
<p>Alles in Allem ein wirklich sehr interessantes Thema, welches ich jedem Webentwickler nur ans Herz legen kann. Einen super Einstieg bietet das Kaazing Gateway und die darin enthaltenen Demos.</p>
<p>Einziges Manko bisher: Kazzing (benötigt Java) ist ein bisschen speicherhungrig,  und ich weiss nicht wie lange mein kleiner VServer damit noch klar kommt <img src='http://lemmingzshadow.net/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://lemmingzshadow.net/163/jittcc-erste-gehversuche-mit-websockets/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

