I started the big Tk script first, the monitor, and then started the smaller, the sender. The command line window I started it from shows incrementing numbers and its sent random number. But, nothing shows up in the monitor graph. I think some of the issue is that the monitor always shows "Not connected." I am not sure how to force it to connect? I am using a windows xp win32, is this the same as what you are using? After using a netstat -a, I see both the Listening on 7070 and the the established, but yet nothing shows up in the graph, I suspect this may be an issue in the the handle_connection subrutine. I uncommented your "print message line." But, nothing is printed. I suspect that handle_connection is not getting far enough to execute handle_connection. Your thoughts or advice? | [reply] |
I am using a windows xp win32, is this the same as what you are using?Eh, sorry no. I use linux, it works. In all likelihood your problem is that, the Tk::fileevent (which monitors and reads the socket), is unreliable on Windows. I'm not going thru the code right now, but that is a very common problem on win32. The quick fix for you, is to remove the fileevent and use a timer ( every 10 or 20 ms ) to read the socket. Thats just an educated guess, and it should work. The fileevent problem was supposedly only on win32 pipes, not sockets. So I'm perplexed, you might post another node and ask win32 users if it works for them. You may have other issues I'm unaware of, like your firewall not allowing the connection, or other localhost issues. Possibly its a blocking problem, does it suddenly spurt out alot of data if you let it run for a few minutes? There are problems with getting non-blocking reads on win32 pipes...but this is a socket? Another way around it, is to switch to Gtk2.....you can use the same idea to write to a Gnome2::Canvas or Goo::Canvas. Gtk2 has a fix for the win32 fileevent problem, with it's comparable Glib::IO::Watch widget.
Its all just a guess on my part, I avoid win32. What you should do, is find some Tk code, that works with sockets on win32, and test to see what the code differences are. Maybe you just need a /r/n for newlines, in the sender script, to tell it to flush, but Perl should handle that automagically on your platform.
print $sock "$send \r\n ";
| [reply] [d/l] |
So, I tried a few things the first was to see if the data was coming across the socket. Here's my simple script:
#!/usr/bin/perl
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalHost => 'localhost',
LocalPort => '7070',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
); die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
while(<$new_sock>) {
print $_;
}
close($sock);
__END__
And it works, data comes across the socket, and shows up in the command window. I do think the problem is in the fileevent. But, I can do the read like I did in my small script, but how do I pass what is read to TK and then use it within its subroutines to build the graph? | [reply] [d/l] |