in reply to perl/tk sockets and fileevent

but the Sara server only gets the message AFTER i abort the GUI client

That is a big clue.

To bring the other monks up to date, I was privately contacted by email about this and proposed that the problem is in his client's socket sub, where he has socket code which will block the gui.

sub lee_socket { print "lee_socket\n"; my $conexion = $Socket_->accept(); my $mensaje; while( defined( my $buffer = <$Socket_> ) ) # read from the socket { print "From client: $buffer" ; $mensaje = $mensaje . $buffer ; } close($Socket_); }

I sent him fileevent code to replace this, but he hasn't responded as to whether it worked or not. The code was part of a simpler example, which wasn't obscured by the spaghetti complexity of the ini files, and long mexican variable names.

$mw ->fileevent($socket, readable => sub { my $line = <$socket>; unless (defined $line) { $mw->fileevent($socket => readable => ''); return; } $log->insert(end => $line); });

My advice, if you want to get people to answer this, is to present a simpler example. With all the complex ini files, and the need to create special files on my system, just to test your script, I will just think " hope someone knows this" and move on. Please try to remake your example code, to be a self contained server and client, which runs on localhost, and demonstrates your problem. Get rid of the ini crap and hardwire in the values, so all we have to do is start the server, and client and see what happens.

If you can't take the time to simplify(and clarify) your problem, why should we?


I'm not really a human, but I play one on earth. flash japh

Replies are listed 'Best First'.
Re^2: perl/tk sockets and fileevent
by HeatSeekerCannibal (Beadle) on Apr 01, 2006 at 00:41 UTC
    ZenTara, You're quite right. When I was pasting the whole code, I tought the same objection you've justifiedly raised here. But at the moment didnt have time for anything else. I am currently working in writing a super compressed version of both scripts, in addition to other chores my boss gives me every half hour or so. Didnt mean to disrespect you or The Monks valuable time by not posting a proper question. On the contrary, I do know everybody has other duties to take care of and I'm grateful you devote time to my question. Anyway, this code you're posting here I had not seen and will try it. Just a question, though, the socket object in it....is it supposed to be extracted from the acceptor method of the socket? Or is it the socket object itself? Thanks in advance for you attention.
      Well the code was from a complete example set which I attached to my email response to your question. I include it below in the readmore, in case you lost the attachments, or some other mailer-incompatibility problems. It is a basic server, and a Tk client. The client sends what is typed in the bottom entry box, and displays the return in the top text box. It is basically what you want to do. You can see that it is basically very simple, when chopped down to just network and Tk code. The fileevent just takes the socket itself, and watches it for when it is readable. When it is, it prints it out. But fileevent will NOT block the rest of the script, like a while loop will. fileevent is basically Tk's version of IO::Select, but adapted to work with the event loop.

      I'm not really a human, but I play one on earth. flash japh
        Ok, Zentara.....it worked!

        You're the man...Send me your address and I'll send a crate of Soles (Mexican beer) your way... ;)

        Besides the fileevent syntax....I needed to write a \n at the end of the string i'm sending to the server. I guess thats why the client was sending the string only after it died.

        Special thanks to g0n and bowie99.....

        heatseekercannibal@hotmail.com