Avri Blog

Blog à l'avricot - Lord Of Castle, java, nosql, Utomia, AvriChat, javascript, Json, Css, Mootools, ajax, php...

Aller au contenu | Aller au menu | Aller à la recherche

Stop Bubble | Start

Mot-clé - AvriChat

Fil des billets - Fil des commentaires

mardi, mai 19 2009

AvriChat : Real time Chat Javascript Comet and Java Server

AvriChat (in development):

related topics :

AvriChat is a real time chat based on mootools.
Server side is based on Java.
Server truly push data to each client (check with firebug !)

AvriChat is based on Moo-Comet and Uvumi Scrollbarr.
(you can use it without Uvumi Scrollbarr)

AvriChat is designed to be used in Lord Of Castle and other projects with Comet.
I will add an Irc connexion very soon.

  • MultiChannel
  • Wips/answer
  • Save x last messages on the channel
  • Admin options (almost done)
  • whois
  • ...

Konwn issue :

  • Little bug with scrollBarr

Download AvriChat

download uncompressed chat sources
download uncompressed avriComet + avriCometd source (cometd wrapper for mootools)
Java source will be released soon.

Exemple :

demo :

Syntax :

  1. // The most easy way :
  2. //we first define the chat
  3. chat = new AvriChat('avriMessage', 'avriMonitor');
  4. //avriMessage : id of the input where the user will type the messages
  5. //avriMonitor : id of the div where the input will be displayed
  6.  
  7. //let's connect !
  8. chat.connect($('name').value, $('password').value);

Options :

  • keepAliveTimer: 20000, //keep-Alive request, in ms. keepAlive's Server has to be at least 2 time this value to avoid disconnections.
  • urlServer: 'http://server.magourex.info/chat/', //url of the server
  • defaultChannel: '', //name of the defaut channel. Server will set his defaut channel if empty
  • autoReconnection: true, //reconnect after a disconnection
  • maxAction: 5, //number of the action saved that you can get with up/down arrows
  • Lots Of Functions(), //all this function are invoked when a data is pushed by the server

//For exemple wisp(_wisp) is invoked to display a wisp on the Monitor.

Main Methods :

  • disconnect () //should be invoked when the user close the current page
  • fireEvent('EveryActionPushedByServer', function (_valueOfTheAction) //throw everytime the server push a data

ChangeLog :

v 0.4 - 01 Jully , 2009

  • Implementation of Bayeux protocol.

v 0.3 - 05 June , 2009

  • Htmlentities used to fix accent bug
  • works with presto.
  • Java code improved
  • Add the typing option which allows you to see what the other users are typing !
  • Use full JSON, parsing of the server's answer really improved (faster)

v 0.2 - 20 May , 2009

  • Avast web shield bug should be really fixed now !
  • I have changed the protocol from Java to javascript. It now use xml and Json inside the xml <data></data>, because Json doesn't fit with so well with this application.

v 0.1 - 19 May , 2009

  • first release

jeudi, mai 14 2009

Comet : header en java : antivirus (avast internet shield) bloque la requete

!!!The full solution : Comment écrire correctement les headers d'une réponse http pour une appliquation comet ?
Le principal inconvenant de Comet est que l'on ne connait pas la taille de l'element à renvoyer. Il est donc impossible de placer dans le header un "Content-length: taille".
La solution toute trouvée serait d'utiliser le header "Transfer-Encoding: chunked" qui spécifie que le message sera envoyé par petit chunk (=morceau).
Seulement voila, les antivirus qui scannent les headers http trouvent qu'un header comme-suivant est insuffisant :

Content-Type text/javascript; charset=ISO-8859-1
Transfer-Encoding chunked

La requête se retrouve alors bloquée par l'antivirus, "en attente", et la réponse ne parvient jamais.

Pour remédier à cela, avast white-list depuis peu les headers ayant dans le nom du serveur le mot clé : DWR-Reverse-Ajax.
Il suffit donc de rajouter "Server: DWR-Reverse-Ajax" pour que avast arrête de bloquer la réponse.

Voici l'ensemble du code qui envoie les headers de avriChat :

  1. public static final byte[] EOL = {(byte)'\r', (byte)'\n' };
  2. /*************************************/
  3. public void send () {
  4. Calendar c = Calendar.getInstance();
  5. String date = c.get(Calendar.DAY_OF_MONTH) + "/" + c.get(Calendar.MONTH) + "/" + c.get(Calendar.YEAR);
  6. try {
  7. this.pw.print("HTTP/1.1 200 OK");
  8. this.pw.write(Server.EOL);
  9. this.pw.print("Date: "+date);
  10. this.pw.write(Server.EOL);
  11. this.pw.print("Server: DWR-Reverse-Ajax Comet AvriChatServer");
  12. this.pw.write(Server.EOL);
  13. this.pw.print("Vary: Accept-Encoding");
  14. this.pw.write(Server.EOL);
  15. this.pw.print("Connection: Keep-Alive");
  16. this.pw.write(Server.EOL);
  17. this.pw.print("Content-Type: text/html");
  18. this.pw.write(Server.EOL);
  19. this.pw.write(Server.EOL);
  20. } catch (IOException e) {
  21. e.printStackTrace();
  22. }
  23. System.out.println(this.content);
  24. this.pw.flush();
  25. }

(Attention, this.pw = new PrintWriter(this.socket.getOutputStream()) ne fonctionne pas.
Il faut envoyer les /r/n en byte avec un write() en utilisant un this.pw = new PrintStream(this.socket.getOutputStream());

Cela fonctionne (pour le moment) pour avast, il faudra voir si d'autres antivirus posent le même problème ou pas...