Chat Client

From: Date: Sun, 24 Nov 2002 18:41:43 +0000
Subject: Chat Client
References: 1  Groups: php.gtk.general 
Request: Send a blank email to php-gtk-general+get-2715@lists.php.net to get a copy of this message
Hi, I m trying to make a code for a chat client , this one connects to a server on 127.0.0.1 port 5005 the server ( written in python waiting for connexions with login <loginname> and brodcast to every connected every entry beginnig with <say> ) here is my code : <?php if (!class_exists('gtk')) { if (strtoupper(substr(PHP_OS, 0,3) == 'WIN')) dl('php_gtk.dll'); else dl('php_gtk.so'); } class chat { function chat () { $this->login_name = "venom"; ////// edit it !!!!! $this->sock = fsockopen("127.0.0.1",5005,&$str_error,&$str2_error); if (!$this->sock) { $stat = "impossible d ouvrir la socket\n"; $stat.=$str_error."\n"; $stat.=$str2_error."\n"; } else $stat = "connexion etablie\n"; $this->window = &new GtkWindow; $this->window->set_title("PHP GTK chat client"); $this->window->set_default_size(500, 600); $this->window->connect('delete_event', array(&$this,'quitApplication') ); $this->vb = &new GtkVBox; $this->text_entry = &new GtkEntry(); $this->text_entry->set_editable(true); $this->vb->pack_start($this->text_entry); $this->window->add($this->vb); $this->button = &new GtkButton('Envoyer'); $this->vb->pack_start($this->button, false, false); $this->button->connect('clicked', array( &$this, 'send_message') ); $this->text = &new GtkText; $this->text->set_editable(false); $this->text->insert_text($stat,0 ); $this->scroller = &new GtkScrolledWindow; $this->scroller->set_policy(GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); $this->scroller->add($this->text); $this->vb->pack_end($this->scroller, true, true, 10); $this->window->show_all(); $this->login(); } function quitApplication() { if ($this->sock) { fputs($this->sock,"logout ".$this->login_name); fclose($this->sock); } Gtk::main_quit(); } function send_message () { $send = $this->text_entry->get_text(); if ($this->sock) { $say_it = "say ".$send."\r\n"; fputs($this->sock,$say_it); $data=fgets($this->sock,1024); $this->text->insert_text($data, 0); $this->text_entry->set_text(""); } else { $err = "erreur de connexion\n"; $this->text->insert_text($err, 0 ); } } function refresh () { print "refresh"; } function login () { if ($this->sock) { fputs($this->sock,"login ".$this->login_name."\r\n"); $response = fgets($this->sock,1024); $this->text->insert_text( $response, 0 ); } $id=Gtk::timeout_add (1000, array( &$this, 'refresh')); } } $a=new chat(); Gtk::main(); ?> I have a problem this "$id=Gtk::timeout_add (1000, array( &$this, 'refresh'));" the refresh command is executed only one time (? why ) and another problem if I had : $d = fgets($this->sock,1024); in the refresh method the program bugged Is anyone could help me making this project working fine?? Many thanx in advance Venom

« previous php.gtk.general (#2715) next »