B
B. W.
I want to send a request from A to B through socket, then B returns the
process result back to A for display. I run B script first then start A
script, but I got error message at B side "can't use an undefined value as a
symbol reference at line 'print $sock_send "$result";'. How can I have both
sides to support sending messages?
the script I created is as:
A side script:
use IO::Socket;
my $sock_recv = new IO::Socket::INET(Localhost
=>'localhost';
LocalPort =>'7071',
Proto =>'tcp',
Listen =>1,
Reuse =>1,
Timeout =>20,
);
die "error create receive socket" unless $sock_recv;
$sock_send = new IO::Socket::INET( PeerAddr
=>'localhost',
PeerPort =>'7070',
Proto =>'tcp',
);
die "error create send socket" unless $sock_send;
print $sock_send "$request";
$new_sock = $sock_recv->accept();
while (defined ($buf = <$new_sock>)) {
print $buf;
}
close ($sock_send);
close ($sock_recv);
B side script:
use IO::Socket;
my $sock_recv = new IO::Socket::INET(Localhost
=>'localhost';
LocalPort =>'7070',
Proto =>'tcp',
Listen =>1,
Reuse =>1,
Timeout =>20,
);
die "error create receive socket" unless $sock_recv;
$new_sock = $sock_recv->accept();
while (defined ($buf = <$new_sock>)) {
$sock_send = new IO::Socket::INET( PeerAddr
=>'localhost',
PeerPort =>'7070',
Proto =>'tcp',
);
die "error create send socket" unless $sock_send;
$result = <some lines to get result from received
$buf>;
print $sock_send "$buf";
close ($sock_send);
}
close ($sock_recv);
thanks,
B.W.
process result back to A for display. I run B script first then start A
script, but I got error message at B side "can't use an undefined value as a
symbol reference at line 'print $sock_send "$result";'. How can I have both
sides to support sending messages?
the script I created is as:
A side script:
use IO::Socket;
my $sock_recv = new IO::Socket::INET(Localhost
=>'localhost';
LocalPort =>'7071',
Proto =>'tcp',
Listen =>1,
Reuse =>1,
Timeout =>20,
);
die "error create receive socket" unless $sock_recv;
$sock_send = new IO::Socket::INET( PeerAddr
=>'localhost',
PeerPort =>'7070',
Proto =>'tcp',
);
die "error create send socket" unless $sock_send;
print $sock_send "$request";
$new_sock = $sock_recv->accept();
while (defined ($buf = <$new_sock>)) {
print $buf;
}
close ($sock_send);
close ($sock_recv);
B side script:
use IO::Socket;
my $sock_recv = new IO::Socket::INET(Localhost
=>'localhost';
LocalPort =>'7070',
Proto =>'tcp',
Listen =>1,
Reuse =>1,
Timeout =>20,
);
die "error create receive socket" unless $sock_recv;
$new_sock = $sock_recv->accept();
while (defined ($buf = <$new_sock>)) {
$sock_send = new IO::Socket::INET( PeerAddr
=>'localhost',
PeerPort =>'7070',
Proto =>'tcp',
);
die "error create send socket" unless $sock_send;
$result = <some lines to get result from received
$buf>;
print $sock_send "$buf";
close ($sock_send);
}
close ($sock_recv);
thanks,
B.W.