<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comentarios en: Crea un chat como el de gMail/Facebook con jQuery</title>
	<atom:link href="http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/</link>
	<description>Desarrollo web, Wordpress, y alguna cosilla más</description>
	<lastBuildDate>Sun, 12 Feb 2012 12:01:25 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>Por: gusarg</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-60380</link>
		<dc:creator>gusarg</dc:creator>
		<pubDate>Wed, 30 Sep 2009 19:12:21 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-60380</guid>
		<description>@gorka,
Echa un vistazo a DWR (http://directwebremoting.org/dwr/index.html) . Funciona bien para reverse ajax, etc. Solo para Java :-)</description>
		<content:encoded><![CDATA[<p>@gorka,<br />
Echa un vistazo a DWR (<a href="http://directwebremoting.org/dwr/index.html" rel="nofollow">http://directwebremoting.org/dwr/index.html</a>) . Funciona bien para reverse ajax, etc. Solo para Java <img src='http://www.anieto2k.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: aNieto2k</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-60355</link>
		<dc:creator>aNieto2k</dc:creator>
		<pubDate>Tue, 29 Sep 2009 15:32:28 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-60355</guid>
		<description>&lt;a  href=&quot;#comment-60343&quot; title=&quot;Responder a Andres&quot; rel=&quot;nofollow&quot;&gt;@Andres&lt;/a&gt;: La licencia dice que no está permitido usar en proyectos como el que tu estás implementando. Tendrás que buscar una alternativa libre o que te permita usarla.
&lt;a  href=&quot;#comment-60354&quot; title=&quot;Responder a gorka&quot; rel=&quot;nofollow&quot;&gt;@gorka&lt;/a&gt;: El HTML y Javascript, puedes usar este mismo, simplemente debes cambiar el fichero chat.php a jsp y te funcionará perfectamente.</description>
		<content:encoded><![CDATA[<p><a href="#comment-60343" title="Responder a Andres" rel="nofollow">@Andres</a>: La licencia dice que no está permitido usar en proyectos como el que tu estás implementando. Tendrás que buscar una alternativa libre o que te permita usarla.<br />
<a href="#comment-60354" title="Responder a gorka" rel="nofollow">@gorka</a>: El HTML y Javascript, puedes usar este mismo, simplemente debes cambiar el fichero chat.php a jsp y te funcionará perfectamente.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: gorka</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-60354</link>
		<dc:creator>gorka</dc:creator>
		<pubDate>Tue, 29 Sep 2009 15:24:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-60354</guid>
		<description>¿Alguien sabe si existe la misma implementación pero para un entorno Java?

Gracias!</description>
		<content:encoded><![CDATA[<p>¿Alguien sabe si existe la misma implementación pero para un entorno Java?</p>
<p>Gracias!</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: Andres</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-60343</link>
		<dc:creator>Andres</dc:creator>
		<pubDate>Mon, 28 Sep 2009 20:36:20 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-60343</guid>
		<description>Gracias Andrés, excelente script, pero tengo una duda yo trabajo como programador y ese chat es para implementarlo en una red social con animo de lucro, que implicaciones tiene utilizarlo es que entiendo poco lo de las licencias, mil gracias</description>
		<content:encoded><![CDATA[<p>Gracias Andrés, excelente script, pero tengo una duda yo trabajo como programador y ese chat es para implementarlo en una red social con animo de lucro, que implicaciones tiene utilizarlo es que entiendo poco lo de las licencias, mil gracias</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: Henry</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-56378</link>
		<dc:creator>Henry</dc:creator>
		<pubDate>Fri, 22 May 2009 04:08:36 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-56378</guid>
		<description>Excelente explicacion del uso del COMET
debo implementarlo en la web www.delchoco.com vere como me va.</description>
		<content:encoded><![CDATA[<p>Excelente explicacion del uso del COMET<br />
debo implementarlo en la web <a href="http://www.delchoco.com" rel="nofollow">http://www.delchoco.com</a> vere como me va.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: Anant Garg</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-56270</link>
		<dc:creator>Anant Garg</dc:creator>
		<pubDate>Mon, 18 May 2009 09:22:46 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-56270</guid>
		<description>@epplestun Hello, the problem with the above example is that if it is used with an Apache server, a number of PHP sessions will remain open and it will completely choke the server. Thus I have mentioned that we require a dedicated server (with root access) so that we can install either MochiWeb/Meteor etc, because using Apache is not the best idea.</description>
		<content:encoded><![CDATA[<p>@epplestun Hello, the problem with the above example is that if it is used with an Apache server, a number of PHP sessions will remain open and it will completely choke the server. Thus I have mentioned that we require a dedicated server (with root access) so that we can install either MochiWeb/Meteor etc, because using Apache is not the best idea.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: epplestun</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-56269</link>
		<dc:creator>epplestun</dc:creator>
		<pubDate>Mon, 18 May 2009 06:27:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-56269</guid>
		<description>&lt;a href=&quot;#comment-56253&quot; title=&quot;Responder a Anant Garg&quot; rel=&quot;nofollow&quot;&gt;@Anant Garg&lt;/a&gt;: Contesto en castellano ya que el blog es en castellano.

Entiendo que dices que es necesario tener un servidor dedicado para poder implementar un servidor HTTP que envie cabeceras PUSH (método real para hacer COMET), pero se puede implementar sin ello. 

Aquí te dejo un ejemplo escrito en MooTools y PHP.


Código Javascript:
&lt;pre&gt;&lt;code&gt;
	var Comet = new Class({
		timestamp : 0,
		url : &#039;./chat.php&#039;,
		noerror : true,
		
		initialize : function() {		
		},
		
		connect : function() {
			var self = this;
			
			this.ajax = new Request.JSON({
				url : self.url,
				method : &#039;get&#039;,
				onSuccess : function(transport) {
					self.timestamp = transport.timestamp;
					self.handleResponse(transport);
				},
				
				onComplete : function(transport) {
					if (!self.noerror) {
						setTimeout(function(){ 
							self.connect() 
							}, 5000);
					} else {
						self.connect();
	        			self.noerror = false;
					}
				
				}
			}).send(&#039;timestamp=&#039; + self.timestamp);
			
			this.ajax.comet = this;
		},
		
		disconnect: function(){ 
		},
		
		handleResponse: function(response) {
			$(&#039;content&#039;).innerHTML += &#039;&#039; + response.msg + &#039;&#039;;
	  	},
	  	
	  	doRequest: function(request){
			new Request({
				url : this.url,
	      		method: &#039;get&#039;
	    	}).send(&#039;msg=&#039; + request);
	  	}
	});
	
	window.addEvent(&#039;domready&#039;, function() {
		var comet = new Comet();
		comet.connect();
		
		$(&#039;form&#039;).addEvent(&#039;submit&#039;, function(e) {
			new Event(e).stop();
			
			comet.doRequest($(&#039;word&#039;).value);
			
			$(&#039;word&#039;).value=&#039;&#039;;
			
			return false;
		});
	});
&lt;/code&gt;&lt;/pre&gt;
Y el código PHP (muy básico, ya que se almacena en un fichero de texto plano .txt):

 parte del path correspondiente al directorio
&lt;pre&gt;&lt;code&gt;
$filename  = dirname(__FILE__).&#039;/datos.txt&#039;;

// almacenamos un nuevo mensajes en el archivo 
$msg = isset($_GET[&#039;msg&#039;]) ? $_GET[&#039;msg&#039;] : &#039;&#039;;
if ($msg != &#039;&#039;){
	//file_put_contents -&gt; escribir una cadena sobre un archivo
	file_put_contents($filename,$msg);
	die();
}

// bucle infinito mientras los datos del archivo no son modificados
$lastmodif    = isset($_GET[&#039;timestamp&#039;]) ? $_GET[&#039;timestamp&#039;] : 0;

//filemtime -&gt; obtiene la hora de modificación del archivo
$currentmodif = filemtime($filename);
while($currentmodif  limpia la cache de estado de un archivo
  	clearstatcache();
  	$currentmodif = filemtime($filename);
}

// devolvemos array en formato json
$response = array();

//file_get_contents -&gt; lee un archivo entero en una cadena
$response[&#039;msg&#039;]       = file_get_contents($filename);
$response[&#039;timestamp&#039;] = $currentmodif;
echo json_encode($response);

//flush -&gt; vaciar el búfer de salida
flush();
?&gt;
&lt;/code&gt;&lt;/pre&gt;
Un saludo :-)</description>
		<content:encoded><![CDATA[<p><a href="#comment-56253" title="Responder a Anant Garg" rel="nofollow">@Anant Garg</a>: Contesto en castellano ya que el blog es en castellano.</p>
<p>Entiendo que dices que es necesario tener un servidor dedicado para poder implementar un servidor HTTP que envie cabeceras PUSH (método real para hacer COMET), pero se puede implementar sin ello. </p>
<p>Aquí te dejo un ejemplo escrito en MooTools y PHP.</p>
<p>Código Javascript:</p>
<pre><code>
	var Comet = new Class({
		timestamp : 0,
		url : './chat.php',
		noerror : true,

		initialize : function() {
		},

		connect : function() {
			var self = this;

			this.ajax = new Request.JSON({
				url : self.url,
				method : 'get',
				onSuccess : function(transport) {
					self.timestamp = transport.timestamp;
					self.handleResponse(transport);
				},

				onComplete : function(transport) {
					if (!self.noerror) {
						setTimeout(function(){
							self.connect()
							}, 5000);
					} else {
						self.connect();
	        			self.noerror = false;
					}

				}
			}).send('timestamp=' + self.timestamp);

			this.ajax.comet = this;
		},

		disconnect: function(){
		},

		handleResponse: function(response) {
			$('content').innerHTML += '' + response.msg + '';
	  	},

	  	doRequest: function(request){
			new Request({
				url : this.url,
	      		method: 'get'
	    	}).send('msg=' + request);
	  	}
	});

	window.addEvent('domready', function() {
		var comet = new Comet();
		comet.connect();

		$('form').addEvent('submit', function(e) {
			new Event(e).stop();

			comet.doRequest($('word').value);

			$('word').value='';

			return false;
		});
	});
</code></pre>
<p>Y el código PHP (muy básico, ya que se almacena en un fichero de texto plano .txt):</p>
<p> parte del path correspondiente al directorio</p>
<pre><code>
$filename  = dirname(__FILE__).'/datos.txt';

// almacenamos un nuevo mensajes en el archivo
$msg = isset($_GET['msg']) ? $_GET['msg'] : '';
if ($msg != ''){
	//file_put_contents -&gt; escribir una cadena sobre un archivo
	file_put_contents($filename,$msg);
	die();
}

// bucle infinito mientras los datos del archivo no son modificados
$lastmodif    = isset($_GET['timestamp']) ? $_GET['timestamp'] : 0;

//filemtime -&gt; obtiene la hora de modificación del archivo
$currentmodif = filemtime($filename);
while($currentmodif  limpia la cache de estado de un archivo
  	clearstatcache();
  	$currentmodif = filemtime($filename);
}

// devolvemos array en formato json
$response = array();

//file_get_contents -&gt; lee un archivo entero en una cadena
$response['msg']       = file_get_contents($filename);
$response['timestamp'] = $currentmodif;
echo json_encode($response);

//flush -&gt; vaciar el búfer de salida
flush();
?&gt;
</code></pre>
<p>Un saludo <img src='http://www.anieto2k.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: Anant Garg</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-56253</link>
		<dc:creator>Anant Garg</dc:creator>
		<pubDate>Sat, 16 May 2009 14:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-56253</guid>
		<description>@epplestun Hello, I am aware of the technologies used by Gmail/Facebook- Comet + Jabber. But I have not implemented these technologies on purpose because most web servers do not have Comet support. In the next version I will be releasing a COMET version but that can be used only by users who have a dedicated server. 

Also, as you have pointed out, the chat history is displayed if the user closes and opens the chat box again. This is a feature similar to Gmail. Only when the user closes the session, the chat history is no longer displayed to the user, although a log is created in a mySQL database.

Feel free to email me if you have any other suggestions.</description>
		<content:encoded><![CDATA[<p>@epplestun Hello, I am aware of the technologies used by Gmail/Facebook- Comet + Jabber. But I have not implemented these technologies on purpose because most web servers do not have Comet support. In the next version I will be releasing a COMET version but that can be used only by users who have a dedicated server. </p>
<p>Also, as you have pointed out, the chat history is displayed if the user closes and opens the chat box again. This is a feature similar to Gmail. Only when the user closes the session, the chat history is no longer displayed to the user, although a log is created in a mySQL database.</p>
<p>Feel free to email me if you have any other suggestions.</p>
]]></content:encoded>
	</item>
	<item>
		<title>Por: epplestun</title>
		<link>http://www.anieto2k.com/2009/05/15/crea-un-chat-como-el-de-gmailfacebook-con-jquery/#comment-56251</link>
		<dc:creator>epplestun</dc:creator>
		<pubDate>Sat, 16 May 2009 09:37:23 +0000</pubDate>
		<guid isPermaLink="false">http://www.anieto2k.com/?p=8206#comment-56251</guid>
		<description>No tiene mala pinta, aparentemente si tiene el mismo estilo que el de gMail o Facebook, pero las técnicas utilizadas en esos chats son diferentes a la utilizada por el chat de Anant Garg. 

Los chat de gMail o Facebook usan la técnica COMET para recibir los mensajes, mientras que el de Anant Garg lo que hace es un setTimeout y ejecutar una petición AJAX cada X tiempo, cosa que no es muy eficiente.

Otra cosa que he visto y no me convence es el modo de almacenar la información y de enviarla, generalmente los chats hacen uso de sockets para realizar conexiones y utilizan un &quot;protocolo&quot; propio de comunicación, lo que hace más robusta la y más eficiente aplicación.

Y por último, cuando comienzas una conversación, y cierras la ventana, la próxima vez que la abres, vuelven a a parecer los mensajes enviados, normalmente una vez que se cierra el chat, la conversación debería quedar almacenada en logs (ya sean texto plano, bases de datos etc), es un problema que depende en que situación puede ser muy grave.

Con ésta crítica no quiero dejar por los suelos el chat, unicamente es una crítica constructiva, indicando cuales son (desde mi punto de vista) los fallos que tiene el chat y donde se podría mejorar :-)</description>
		<content:encoded><![CDATA[<p>No tiene mala pinta, aparentemente si tiene el mismo estilo que el de gMail o Facebook, pero las técnicas utilizadas en esos chats son diferentes a la utilizada por el chat de Anant Garg. </p>
<p>Los chat de gMail o Facebook usan la técnica COMET para recibir los mensajes, mientras que el de Anant Garg lo que hace es un setTimeout y ejecutar una petición AJAX cada X tiempo, cosa que no es muy eficiente.</p>
<p>Otra cosa que he visto y no me convence es el modo de almacenar la información y de enviarla, generalmente los chats hacen uso de sockets para realizar conexiones y utilizan un &#8220;protocolo&#8221; propio de comunicación, lo que hace más robusta la y más eficiente aplicación.</p>
<p>Y por último, cuando comienzas una conversación, y cierras la ventana, la próxima vez que la abres, vuelven a a parecer los mensajes enviados, normalmente una vez que se cierra el chat, la conversación debería quedar almacenada en logs (ya sean texto plano, bases de datos etc), es un problema que depende en que situación puede ser muy grave.</p>
<p>Con ésta crítica no quiero dejar por los suelos el chat, unicamente es una crítica constructiva, indicando cuales son (desde mi punto de vista) los fallos que tiene el chat y donde se podría mejorar <img src='http://www.anieto2k.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
</channel>
</rss>

