hari9 has asked for the wisdom of the Perl Monks concerning the following question:
Can somebody please suggest how I could dynamically update a variable's value in client's script,each time I call the server(which sends a value to client that is assigned to this client's variable).
for eg.
If client has a variable $a=1, that it sends to server.
server sends back client $t=2, that is assigned to $a of client.
Now when the same client establishes a connection with the server next time, it would send $a=2 ( and not $a=1).
for the following Server and Client codes:
ServerClient#tcpserver.pl use Switch; use feature qw(switch say); use IO::Handle; use IO::Socket::INET; $|=1; my ($socket,$client_socket); $socket = new IO::Socket::INET ( #LocalHost => '127.0.0.1', LocalPort => '9000', Proto => 'tcp', Listen => 5, Reuse => 1) or die "ERROR in Socket +Creation : $!\n"; while(1) { $client_socket = $socket->accept(); while(defined(my $data=<$client_socket>)) { $a=$data; } if($a eq 1) { $t=$a++; } $client_socket->shutdown(0); print $client_socket $t; } $socket->close();
Thanks.#tcpclient.pl use feature qw(switch say); use IO::Socket::INET; use IO::Handle; my($status,$md_self,@md_others); $|=1; $a=shift||1; my ($socket,$buffer); print "TCP Connection Success.\n"; $socket = new IO::Socket::INET (PeerHost => '127.0.0.1', PeerPort => '9000', Proto => 'tcp', ) or die "ERROR in Socket Creation + : $!\n"; # write on the socket to server. print $socket $a; $socket->shutdown(1); $t=<$socket>; print $t; $a=$t; $socket->close();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: dynamic socket communication
by zentara (Cardinal) on Aug 05, 2010 at 17:26 UTC | |
by MidLifeXis (Monsignor) on Aug 05, 2010 at 17:46 UTC | |
|
Re: dynamic socket communication
by jethro (Monsignor) on Aug 05, 2010 at 17:27 UTC | |
|
Re: dynamic socket communication
by wol (Hermit) on Aug 06, 2010 at 15:15 UTC |