Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re^2: asynchronous socket communication with perl tk

by simonz (Sexton)
on Sep 27, 2013 at 08:56 UTC ( #1055948=note: print w/replies, xml ) Need Help??

in reply to Re: asynchronous socket communication with perl tk
in thread asynchronous socket communication with perl tk

I even modified the server code to make it working, i removed the gui portion. Now when i am starting the server and then starting the client from another terminal , it works. However, the first time when I start, it prints msg1, then stops. Again when i start , it prints msg1 amd msg2. Similarly third time msg1, msg2,msg3 .

My question is

1. why not all the five messages msg1..msg5 are getting printed in one go when i start

The client code remains as it is as posted before
Can someone please explain me the flow of the code.

my $server; $server = IO::Socket::INET::->new( Proto => 'tcp', LocalPort => 55555, Listen => 1, Reuse => 1 ) or die "Server can't start: $!"; my $readable_handles = new IO::Select(); my $buf; while (my $client = $server->accept) { #Infinite loop # select() blocks until a socket is ready to be read or written my ($new_readable) = IO::Select->select($readable_handles, undef, undef, 0); # print "Inside while \n"; # If it comes here, there is at least one handle # to read from or write to. For the moment, worry only about # the read side. $readable_handles->add($client); foreach my $sock (@$new_readable) { if ($sock == $server) { my $new_sock = $sock->accept(); # Add it to the list, and go back to select because the # new socket may not be readable yet. $readable_handles->add($new_sock); } else { # It is an ordinary client socket, ready for reading. $buf = <$sock>; if ($buf) { # .... Do stuff with $buf #$$status_ref = $buf; print $buf ; } else { # Client closed socket. We do the same here, and remov +e # it from the readable_handles list $readable_handles->remove($sock); #close($sock); } } } }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1055948]
[Tux]: Corion++ hippo++
[ovedpo15]: it isn't homework. its a module I use at work. The process to add additional module isn't worth it. p.s never heard a university course which teach perl
[marto]: there are many, to this day.
[ovedpo15]: @Corion Yes I use the regex you showed me. its very good regex. although now i need to know that substring unit that comma
marto mad corrections to one around 18 months ago
[ovedpo15]: my code checks the value after that comma, if it isn't valid it will remove it. so I would like to remove the substring after that comma meaning getting the string before comma.
[hippo]: Are you sure that Text::CSV_XS isn't already installed at your work? It's such a useful module that it might well be there.
[marto]: pointing out the advantages of cpan modules is well worth in, as both developer and $client/$company benefit greatly
[Tux]: $src =~ m{^(.*),(.*)$/ and $2 !~ $valid and $src = $1;
[Tux]: s,/,},

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2018-05-27 10:47 GMT
Find Nodes?
    Voting Booth?