V
Vikrant
hi
In the following code i am receving data from the client in a
buffer($sBuffer) and concatenating it into a another variable
$sData_Recevied.
My problem is that i can not understand what condition i should give in
do-while loop to exit if a certain time period elapses without any
data being received from the client. I have already tried the code
below, but it is not exiting the loop after 10 seconds.
########################################################################
#!/usr/bin/perl -w
use Socket;
$SOCKET_PORT =36545;
#Create
socket(hSERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$iListener_Socket = sockaddr_in($SOCKET_PORT, INADDR_ANY);
#Binding
bind(hSERVER,$iListener_Socket)
or die "Couldn't connect to Remote Host : $!\n";
#Listen
listen(hSERVER,4);
accept(hCLIENT,hSERVER);
$iEndTime = time() + 10;
do
{
recv(hCLIENT,$sBuffer,1024,0); #Receving Data at Socket
$sData_Recevied.=$sBuffer;
}while($iEndTime > time());
$sReturnXML = "Data has been recevied";
send(hCLIENT,$sReturnXML,0);
close(hCLIENT);
close(hSERVER);
#################################################################################
Thanks
Vikrant
In the following code i am receving data from the client in a
buffer($sBuffer) and concatenating it into a another variable
$sData_Recevied.
My problem is that i can not understand what condition i should give in
do-while loop to exit if a certain time period elapses without any
data being received from the client. I have already tried the code
below, but it is not exiting the loop after 10 seconds.
########################################################################
#!/usr/bin/perl -w
use Socket;
$SOCKET_PORT =36545;
#Create
socket(hSERVER, PF_INET, SOCK_STREAM, getprotobyname('tcp'));
$iListener_Socket = sockaddr_in($SOCKET_PORT, INADDR_ANY);
#Binding
bind(hSERVER,$iListener_Socket)
or die "Couldn't connect to Remote Host : $!\n";
#Listen
listen(hSERVER,4);
accept(hCLIENT,hSERVER);
$iEndTime = time() + 10;
do
{
recv(hCLIENT,$sBuffer,1024,0); #Receving Data at Socket
$sData_Recevied.=$sBuffer;
}while($iEndTime > time());
$sReturnXML = "Data has been recevied";
send(hCLIENT,$sReturnXML,0);
close(hCLIENT);
close(hSERVER);
#################################################################################
Thanks
Vikrant