in reply to Re^2: endless loops for server and tk
in thread endless loops for server and tk

Okay. Here are three separate minimal programs, and one composite that joins them all together. I have used your Tk program, cleaned up a lot. Sorry that your comments are missing, but I don't read Gernman and they were just in the way of seeing what was going on. You should really try to be a little more consistant with your code layout also.

This is the standalone server that listens and responds to 5 different udp ports:

And this is the standalone client. It talks to all of the ports on the server for testing and demo, but would normally only talk to one. When used as the heartbeat thread withing the combined app, it would also talk to all 5 clients.

And here is my cleaned up and working version of your Tk code. I am posting it separately because you should maintain all 3 standalone apps as testbeds and reference points, as well as the combined app. It is much easier to test changes in the individual apps and, once you are satisfied they are working, c&p the changes into the combined app. It make seem extra work, but think of the separate apps and testcases.

#!/usr/bin/perl use Tk; use Tie::File; my $liste; my $liste_font; my $breite=100; my $the_selectmode = "extended"; my $enter; my @array_file; my $mw = MainWindow->new(); my $frame1 = $mw->Frame( -width=>50, -height=>50, -bg=>"seashell" ); my $frame2 = $mw->Frame( -width=>5, -height=>5, -bg=>"grey80" ); $liste_font = $mw->fontCreate(-family=>"courier", -size=>7 ); my $liste = $frame1->ScrlListbox( -setgrid=>1, -scrollbars=>"se", -background=>"lemonchiffon3", -borderwidth=>3, -highlightthickness=>10, -height => 30, -selectforeground=>"blue", -selectbackground=>"green", -relief=>"ridge", -exportselection => 1 )->pack(-side=>"right", -expand=>1, -fill=>"both"); my $exitButton = $frame2->Button( -text=>"Schliessen" ,- command=>"exit" , -bg=>"red" , -activebackground=>"red", -activeforeground=>"cyan" )->pack( -anchor=>"w", -padx=>10 , -pady=>15 , -ipady=>10, -fill=>"x" ); $frame1->pack(-side => 'left' ,-expand=>1 ,-fill=>"both"); $frame2->pack(-side => 'right',-expand=>1 ); $frame2->pack(-expand=>1 ,-fill=>"both"); $mw->repeat(10, \&fill_with_tie ); MainLoop; sub fill_from_file { my $file = "meinfile.txt"; my $line; $liste->delete(0,"end"); if ( -s $file ) { open(DATEI, "<$file") or die $!; while ($line = <DATEI>) { chomp $line; $liste->insert(0,$line); } close(DATEI); } } sub fill_with_tie { my $file = "meinfile.txt"; my $line; my $elem; $liste->delete(0,"end"); if ( -e $file ) { tie @array_file, "Tie::File", $file || die $!; foreach $elem (@array_file) { chomp $elem; $liste->insert(0,$elem); } untie @array_file; } else { print "Kann $file nicht oeffnen $!\n"; } }

And finally, the combined, threaded app. The modifications are minimal. Each thread is a direct C&P from the standalone version.

In particular, there is very little shared data, as it is not clear what else you want to do or what else you need to share, but it should give you a starting point. My purpose is to demonstrate the simplicity of combining the code.

After that, you are responsible for adding whatever extras you need. I'm willing to help you make your additions, but please don't post reams and reams of code with huge chunks commented out and reams and reams of comments that I cannot understand--just delete them from the post--otherwise I am apt to be put off.

To answer your question from Re^2: Displaying text in columns, I've used spoiler tags, rather than readmore tags, despite this usage being frowned upon, because spoiler tags do not get expanded until you choose to click on them whereas readmore tags are expanded whenever you view the post directly. This way, you can read the text of the post as a coherent whole without having to scroll past loads of code.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
"Too many [] have been sedated by an oppressive environment of political correctness and risk aversion."