PHP-GTK2 Cookbook Forum
Welcome, Guest
Please Login or Register.    Lost Password?
Re:Client Server (1 viewing) (1) Guest
Go to bottom Post Reply Favoured: 0
TOPIC: Re:Client Server


#574
ciprian_dimofte (User)
Senior Boarder
Posts: 46
graphgraph
User Offline Click here to see the profile of this user
Client Server 3 Years, 9 Months ago Karma: 0  
I'm having a personal effort to build a PHP-GTK2 client/server application, whereas I would build an instant messenger.

Can anyone help out with some very basic sample code on how to broadcast IMs with either sockets, netsend, whatever... ?

So what I need is something very basic. One piece of code on the client side and one on the server side so I can see exactly what's needed, etc.

I understood exactly how to use the GtkTextView and TreeView, ListStore, TreeStore, and managed to build the overall GUI for this application. I just need the above requested pieces of code, for a basic client/server communication with PHP-GTK2.

Thank you VERY much for your efforts in helping us all out.
Best Regards, and looking forward to hearing from you.

CD
 
  The administrator has disabled public write access.

#585
kksou (Admin)
Admin
Posts: 1599
graph
User Online Now Click here to see the profile of this user
Re:Client Server 3 Years, 9 Months ago Karma: 23  
Take a look at

phpICQ

It might be the example you want.

Regards,
/kksou
 
  The administrator has disabled public write access.

#589
kksou (Admin)
Admin
Posts: 1599
graph
User Online Now Click here to see the profile of this user
Re:Client Server 3 Years, 9 Months ago Karma: 23  
By the way, this is PHP specific, and not PHP-GTK specific. Yes, you can design the frontend using PHP-GTK. But the backend is just plain old PHP.

If it's plain old PHP, I believe there should be a lot of examples scattering around the net (unlike PHP-GTK). Try google for it, or go to some PHP forums to ask some experts there. You should be able to find something useful and relevant.

Regards,
/kksou
 
  The administrator has disabled public write access.
#590
ciprian_dimofte (User)
Senior Boarder
Posts: 46
graphgraph
User Offline Click here to see the profile of this user
Re:Client Server 3 Years, 9 Months ago Karma: 0  
well I've managed to make my server... here's some code I've used inspired by the php.net examples:

Code:
<?php
$clients = array();
$socket = @socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
@socket_bind($socket,'172.16.213.31',2622);
@socket_listen($socket);
@socket_set_nonblock($socket);

while(true){
    if(($newc = @socket_accept($socket)) !== false){
        $clients[] = $newc;
		echo $newc." has just connected !\n";
		socket_send($newc, "1", 4, 0);
		$responce = socket_read($newc, 5);
		if($responce != "2"){
			echo "\t\t".$newc." has gone away...\n";
		}
    }
	usleep(500000);
}

?>
and I just needed to know how that timeout_add or idle_Add works so I can make the two client/server communicate in a timely fashion. I've seen that clearly in the codes on the icq applications you've directed me to. Thanks again. CD
 
  The administrator has disabled public write access.
#591
ciprian_dimofte (User)
Senior Boarder
Posts: 46
graphgraph
User Offline Click here to see the profile of this user
Re:Client Server 3 Years, 9 Months ago Karma: 0  
and thus would have been my client
Code:
<?php
define("GLB", "lib/");

$glade = new GladeXML(GLB.'xml/client.glade');
$glade->signal_autoconnect();



function connect(){
	$fp = fsockopen("172.16.213.31",2622, $errno, $errstr, 1);

	if($fp) {
		$ping = fread($fp,1024);
		if($ping == "1"){
			fwrite($fp, "2");
		}
	}
	fclose($fp);
}


Gtk::main();

function gtk_main_quit(){
	Gtk::main_quit();
}

?>
But heck of course this only worked once when I clicked the Connect button... it wouldn't stay alive to query the server for ping replies, etc every 0.5 seconds or whatever. I just needed a clear explanation on how to use that timeout_add or idle_add that I just saw somewhat clearer in the ICQ example. CD
 
  The administrator has disabled public write access.
#592
kksou (Admin)
Admin
Posts: 1599
graph
User Online Now Click here to see the profile of this user
Re:Client Server 3 Years, 9 Months ago Karma: 23  
Yes, these two are php-gtk specific.

Take a look at the following examples and you'll understand how to use these two functions.

idle_add()
Sample Code 68: How to display progress bar while processing long task - Part 2 using_idle_add?

timeout_add()
Sample Code 464: How to set up a countdown timer - Part 1?

Regards,
/kksou
 
  The administrator has disabled public write access.



Go to top Post Reply
Powered by FireBoardget the latest posts directly to your desktop

Blog - Forum - Privacy Policy - Contact Us
Copyright © 2006-2012. kksou.com. All Rights Reserved