Re: refresh problem
| From: | silver_dragoon | Date: | Fri, 23 May 2003 17:35:21 +0000 |
| Subject: | Re: refresh problem | ||
| References: | 1 | Groups: | php.gtk.general |
| Request: | Send a blank email to php-gtk-general+get-3473@lists.php.net to get a copy of this message | ||
Well,
I realize I wasn't clear at all, so I rewrote my code a little, and I give
it here, hoping someone will guess what's going wrong.
I've tried many of your tricks, but none of them succeeded.
I've put some gtk::main_iteration after the socket_read, but I doesn't help
me refreshing my display.
So here is the code :
class irc_connection
{
var $socket;
var $console;
var $usercommand;
function irc_connection()
{
$window = &new GtkWindow;
//here is the code building some widgets and the main window,
$this->console = &new GtkText();
$this->console -> set_editable(false);
$this->console -> set_word_wrap(true);
//other stuff
$window -> show_all();
}
function irc_connect($server, $port)
{
$this->socket = socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$connection = socket_connect($this->socket,$server,$port);
socket_write($this->socket, "USER PHPGTK UNKNOW UNKNOW :silver_d\r\n");
socket_write($this->socket, "NICK :silver_d\r\n");
return true;
}
function parse_server_msg($servermsg)
{
//réécrire le code car une seule ligne est transmise
$commande = explode(' ', trim($servermsg));
if ($commande[0] == 'PING')
{
$reponse = "PONG ".$commande[1]."\r\n";
socket_write($this->socket, $reponse);
echo $reponse;
}
}
function update_irc()
{
if ($datairc = @socket_read($this->socket, 10240))
{
$stack = explode("\r\n", trim($datairc));
echo "$datairc";
foreach ($stack as $cle => $servermsg)
$this->parse_server_msg($servermsg);
$this->console-> insert($font, $color, null, $datairc);
}
while (gtk::events_pending()) gtk::main_iteration();
return true;
}
function refresh()
{
$this->console->thaw();
while (gtk::events_pending()) gtk::main_iteration();
return true;
}
function __sleep()
{
socket_close($this->socket);
}
}
and the main code :
include('classes.php');
set_time_limit(0);
if (isset($strStyle)) {
GTK::rc_parse( GTK::rc_get_theme_dir() . "/" . $strStyle . "/gtk/gtkrc");
}
$ircserver = new irc_connection;
$ircserver -> irc_connect('irc.epiknet.org', 6667);
gtk::timeout_add('20', array(&$ircserver, "update_irc"));
gtk::timeout_add('2', array(&$ircserver, "refresh"));
gtk::main();
well... sorry for writing my code here but i really can't get it to work...
thank you a lot, again :)
++ silver_d