CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Other Programming Languages: PHP:
Problems sending and receiving data between php and perl ?

 



haonhien
New User

Nov 17, 2011, 11:56 PM

Post #1 of 1 (18257 views)
Problems sending and receiving data between php and perl ? Can't Post

Hello all ! I am from Vietnam!

I have a problem in sending and receiving data between php and perl socket:

-Problem:
+php can not send all byte data to perl socket
+Perl socket can not receiving all data from php .

Here code php:

Code
function save(){ 
unset($_SESSION['info']);
unset($_SESSION['data']);
global $config,$ip;
$start=$_POST['config'];
$fp = fsockopen($_SESSION['ip'], $config['port'], $errno, $errstr, 30);
if(!$fp)
{
$_SESSION['info']="Not connect ";
transfer("Not connect".$ip, "index.php?com=server&act=info");
}
else
{
$_SESSION['info']="Save config - ".$ip;

fwrite($fp,$start);


transfer("Sending data to ".$ip, "index.php?com=server&act=info");
}
}


Here code perl socket:

Code
#!/usr/bin/perl 
use strict;
use warnings;
use Carp;
use POSIX qw( setsid );

use IO::Socket;

$| = 1;

my $socket = new IO::Socket::INET (
LocalHost => '192.168.150.3',
LocalPort => '5000',
Proto => 'tcp',
Listen => 5,
Reuse => 1
);

die "Coudn't open socket" unless $socket;

print "\nTCPServer Waiting for client on port 5000";
my $client_socket = "";

while ($client_socket = $socket->accept())
{


my $recieved_data =" ";
my $send_data=" ";

my $peer_address = $client_socket->peerhost();
my $peer_port = $client_socket->peerport();

print "\n I got a connection from ( $peer_address , $peer_port ) ";

print "\n SEND( TYPE q or Q to Quit):";
$client_socket->recv($recieved_data,20000);
#while (defined($recieved_data = <$client_socket>)) {

if ( $recieved_data eq 'q' or $recieved_data eq 'Q' )
{
close $client_socket;
last;
}
elsif ($recieved_data eq 'start' or $recieved_data eq 'START' )
{
$send_data = `/etc/init.d/squid start`;
}
elsif ($recieved_data eq 'restart' or $recieved_data eq 'RESTART' )
{

$send_data = `/etc/init.d/squid restart`;
}
elsif ($recieved_data eq 'stop' or $recieved_data eq 'STOP' )
{
$send_data = `/etc/init.d/squid stop`;
}
elsif ($recieved_data eq 'hostname' or $recieved_data eq 'HOSTNAME' )
{
$send_data= `hostname`;
}
elsif ($recieved_data eq 'view-config' or $recieved_data eq 'VIEW-CONFIG' )
{
$send_data = `cat /etc/squid/squid.conf` ;
}
else
{
# print $recieved_data;
open OUTPUT_FILE, '> /root/data' or die("can not open file");

print OUTPUT_FILE $recieved_data;
close OUTPUT_FILE
}
#}
if ($send_data eq 'q' or $send_data eq 'Q')
{

$client_socket->send ($send_data);
close $client_socket;
last;
}
else
{
$client_socket->send($send_data);
}

}


Thank you all!

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives