tballah
asked on
Display output from server for every command sent by client via Socket
There are 4 commands that my client needs to send to server using socket named TCP_SOCK in sequence and my client needs to display the output from server for every command sent to it. How can I achieve this goal? Every command is ended by semi-column ";" to ask server to execute it.
I use "print scalar <TCP_SOCK>;" but the client cannot display all the text from the sever, it misses some texts. When I try to use:
while ($line = <>)
{
print $line;
}
only the first command is executed, not continue with the other commands.
I use "print scalar <TCP_SOCK>;" but the client cannot display all the text from the sever, it misses some texts. When I try to use:
while ($line = <>)
{
print $line;
}
only the first command is executed, not continue with the other commands.
select TCP_SOCK; $| = 1; select STDOUT;
my @command;
$command[0] = qq/Do the first one;/;
$command[1] = qq/Do the second one;/;
$command[2] = qq/Do the third one;/;
$command[3] = qq/Do the fourth one;/;
print TCP_SOCK $command[0];
print TCP_SOCK $command[1];
print TCP_SOCK $command[2];
print TCP_SOCK $command[3];
close TCP_SOCK;
ASKER
The response from the server contains many lines and I follow the solution from the sample code you provide to me, I can see only the first line from the output, there are many other lines missing. I can see all the lines when I use while loop but it blocks me from executing other commands.
If the response is multiline, how do you know which line is the last line of the response?
ASKER
The response for the first command looks like:
+++ SGSN 2010-09-02 22:10:27
O&M #852
%%LGI:OP="ballah",PWD="*** **",SER="M ML Backup";%%
RETCODE = 0 Execution succeeded
--- END
The last line is "--- END". From the sample of your code provided I can see only the first line "+++ SGSN 2010-09-02 22:10:27". If I do loop with while I can see all the lines responded from the server but it could not exit loop and it loops forever and I cannot execute other commands. Please see my code.
+++ SGSN 2010-09-02 22:10:27
O&M #852
%%LGI:OP="ballah",PWD="***
RETCODE = 0 Execution succeeded
--- END
The last line is "--- END". From the sample of your code provided I can see only the first line "+++ SGSN 2010-09-02 22:10:27". If I do loop with while I can see all the lines responded from the server but it could not exit loop and it loops forever and I cannot execute other commands. Please see my code.
select TCP_SOCK; $| = 1; select STDOUT;
my @sgsn_command;
$sgsn_command[0] = qq/LGI:OP="$user_name",PWD="$password",SER="MML Backup";/;
$sgsn_command[1] = qq/SAVE CFG:;/;
$sgsn_command[2] = qq/SET FTPENABLE:;/;
$sgsn_command[3] = qq/LGO:;/;
exec_mml($sgsn_command[0]);
exec_mml($sgsn_command[1]);
exec_mml($sgsn_command[2]);
exec_mml($sgsn_command[3]);
close TCP_SOCK;
}
sub exec_mml
{
print TCP_SOCK shift;
while (<TCP_SOCK>)
{
print;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
sub exec_mml
{
print TCP_SOCK shift;
while ()
{
print;
last if /END/;
}
}
{
print TCP_SOCK shift;
while ()
{
print;
last if /END/;
}
}
Open in new window