Hi There.

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:

Server
#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();
Client
#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();
Thanks.

In reply to dynamic socket communication by hari9

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.