Teen Programmers Unite  
 

 

Return to forum top

perl's Autoflash ??

Posted by Perl [send private reply] at February 17, 2003, 09:54:13 PM

i need help again..
Here is the situation:

#///////////////////////////////////////////////////////
use IO::Socket;
use IO::Handle;
$site = 'localhost';
$soc = IO::Socket::INET->new( PeerAddr => $site,
PeerPort => 2346,
Proto => 'tcp',
Type => SOCK_STREAM
) or die "can't create socket\n";
#///////////////////////////////////////////////////////

$new="frame.pl";
print $soc "$new\n";

#After i had pass the frame.pl to the socket..i need to pass another file name to the socket again..

$new1="frame1.pl";
print $soc "$new1\n";

#It wont work..so i decided to use atuoflash to clear the $soc..am i rite??

$new="frame.pl";
print $soc "$new\n";
$soc->autoflush();
$new1="frame1.pl";
print $soc "$new1\n";

# But after i had added the autoflash, it wont work too???

Thanks!

Posted by buzgub [send private reply] at February 18, 2003, 03:30:16 AM

do more error checking. This code is your friend:

or die "Could not perform doodaddywhatsit: $!";

Posted by Perl [send private reply] at February 18, 2003, 08:17:02 AM

It did not have error..it just wont work..

Posted by taubz [send private reply] at February 18, 2003, 05:12:54 PM

What **exactly** won't work?

Posted by Perl [send private reply] at February 18, 2003, 06:55:03 PM

Well..the '$new' that accept 'frame.pl' works only...frame.pl is run but but not '$new1' that accept 'frame1.pl' works

cos i bind both of them to the same $soc..

the only solution i found so far..was to close the $soc and open a new one and then bind the '$new1' to it..but it was inefficient..

But the second solution i was trying to find was using autoflush to flush not flash(i put flash for my topic..lolz)
the $soc after it had bind the '$new'...after that it could continue to bind '$new1' but it wont works...

Posted by taubz [send private reply] at February 18, 2003, 08:29:21 PM

There's no problem in the program you posted. It will send the data just fine as far as I can tell. So, either the server program isn't working or you aren't sending the right data to the server to get the results you want.

- taubz

Posted by taubz [send private reply] at February 18, 2003, 08:30:46 PM

And "binding" doesn't really have anything to do with what you're doing here. You're sending data through a socket.

Posted by Perl [send private reply] at February 18, 2003, 08:57:13 PM

i think i had used the bind word wrongly...

ya..i was sending data through the socket but i am sending 2 data (the $new[contain the string'frame.pl'] and $new1 [contain the string'frame1.pl']) through the $soc..my server socket run the frame.pl ONLY but not the frame1.pl...

i think maybe because the $soc is 'busy' with $new cos $new was the first to pass through the socket and then follow by the $new1...
when i used these

$new="frame.pl";
print $soc "$new\n";

frame.pl was passed then i did these again..changing the filename and declare a new variable.

$new1="frame1.pl";
print $soc "$new1\n";

In the end..
only frame.pl was run at my server side..not the frame1.pl

SO i thought of clearing whatever in the $soc first before $new1 was used

$soc->autoflush();

but it still dun work at all...

so my concern is how am i going to run the frame.pl and frame1.pl together??? thanks lots!!!!

Posted by taubz [send private reply] at February 18, 2003, 09:45:37 PM

Again, the problem is not with what Perl commands to use. The question is, what is the server program designed to do? There's no sense in floating around words like "busy" and "binding" if you don't understand what the server program might be busy with.

Find out what's on the other end of your socket, and learn what it's specifications are.

- taubz

Posted by Perl [send private reply] at February 19, 2003, 03:25:31 AM

i know what is going on at the end of the server socket...but i just need to know how am i going to refesh the $cl??? possible??

Posted by buzgub [send private reply] at February 19, 2003, 05:04:41 AM

Try modifying your server so that it prints information about what it will do know, rather than actually doing it. That should help you verify whether or not your server is working properly - it may not be doing what you expect.

Posted by Perl [send private reply] at February 19, 2003, 07:13:25 PM

i think my problem is my server program allows only one command (which file to run) per client...

if i want to run multiple commands (many files) per client..
my server accepts only the first command (first file) and then it wont run again unless i close and reopen the socket for each command(which file to run) which proves to be ver bad..not good at all although it works..

Posted by buzgub [send private reply] at February 19, 2003, 11:33:19 PM

well then, fix your daemon. Use the file-reading example I gave in one of your other twenty-million threads as an example, and you should be okay.

Posted by Perl [send private reply] at February 20, 2003, 12:58:40 AM

i had decided to give one last try to see if anyone know these problem

Client side socket
####################################
#These part was sending the name of the file to the server socket side
####################################
print"<p align=center><b>Shutting MD\n</b></p>\n";
$new="frame.pl";
#$new="/md/bin/mdcron MANAGER SHUT";
print $soc "$new\n";
#########################################
#These part was to recieve the results of the called file
#########################################
while($date = <$soc>)
{

chop($date);
if($date ne""){
print "it is $date\n";
}
}
####################################
#These part was sending the name of the second file to the server socket side
####################################
$new1="frame1.pl";
#$new1="/md/bin/mdcron MANAGER SHUT";
print $soc "$new1\n";
#########################################
#These part was to recieve the results of the called file
#########################################
while($date = <$soc>)
{
chop($date);
if($date ne""){
print "it is $date\n";
}
}
close $soc;
//////////////////////////////////
BUT ONLY THE FRAME.PL WAS SENT...
############################
#These part was from the server socket
###########################
print "Server is working\n";
while($cl = $server->accept())
{
open(INFO,"perl $command|") || die("can't open file.pl: $!");
while ($wc=<INFO>)
{
chop($wc); #Getting Rid of Spaces!
if ($wc ne ""){
print $cl "$wc\n";
}
#ALSO ONLY THE RESULTS OF THE FIRST CALLED FILE--FRAME.PL #WAS RETURN!!
}

close $cl;

}
/////////////////////////////
PROBLEM:even if i had managed to send the 2 filenames over to the socket...only the results of the first file--frame.pl was returned....anyone..thaks..while i'm thinking of something else to solve it..

Posted by Perl [send private reply] at February 20, 2003, 01:03:03 AM

It is fine if nobody answer..Thank you.!!~~!~

Posted by buzgub [send private reply] at February 21, 2003, 03:05:04 AM

I'm using icky pseudocode in this post, because I think that's the best way to help you think about the program you're writing.

Your server looks like this:

while (new_connections){
	get_command_from_connection
	open_command
	while (more_output_from_command)
		print_line_to_client
	close_command
}


However, it should look like this:

while (new_connections){
	while (more_commands_on_connection){
		open_command
		while (more_output_from_command)
			print_line_to_client
		close_command
	}
}


I hope that all makes sense to you.
Posted by Perl [send private reply] at February 23, 2003, 07:38:55 PM

Thanks buzgub...yr suggestions actually works...tried that before already...

Everythings works fine IF only the print_line_to_client is not there

once i comment off print_line_to_client, it works, able to run mulitples files but once the print_line_to_client is not comment off, it can only run the first file.

###########################################################
while($cl = $server->accept())
{


while(chop($command=<$cl>)){ #receiving the info from the client

open(INFO,"perl $command|") || die("can't open $command: $!");
while($wc=<INFO>){

chop($wc); #Getting Rid of Spaces!

print"$wc\n";
#print $cl "$wc\n";#This is the Key

}
close $command;
}


}

You must be logged in to post messages and see which you have already read.

Log on
Username:
Password:
Save for later automatic logon

Register as a new user
 
Copyright TPU 2002. See the Credits and About TPU for more information.