indigo1tx has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl
#telcel server
$ETX = chr(03);
$STX=chr(03);
use IO::Socket;
use Sys::Hostname;
my $sock = new IO::Socket::INET(
LocalHost => 'localhost',
LocalPort =>10019,
Proto => 'tcp',
Listen => SOMAXCONN,
Reuse => 1);
$sock or die "no socket :$!";
STDOUT->autoflush(1);
$|=1;
my($new_sock, $buf);
# print "$buf\n";
while ($new_sock = $sock->accept()) {
# got a client connection, so read
# line by line until end-of-file
# print "BUF: $buf";
while (defined($buf = <$new_sock>)) {
# while (defined($buf = split(/$ETX/,<$new_sock>))) {
foreach ($buf) {
# chop($buf);
$buf =~ s/98/99/gi;
print($new_sock "$buf"),
print "$buf\n";
}
}
close $new_sock;
}
The client
#!/usr/bin/perl
# client2way.pl - a client that writes to
# and reads from a server
require "./cgiCommon";
use IO::Socket;
#my $host = shift || '10.252.1.41';
$host = shift || 'localhost';
#my $port = shift || 10018;
my $port = shift || 10019;
my $sock = new IO::Socket::INET(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp');
$sock or die "no socket :$!";
$sock->autoflush(1);
use DBI;
if ($sock){
print "Connected to $host\n\n";
}
$counter="0";
while ($counter < 30){
# send message to server
#print $sock "HELLO\n";
# print server response to STDOUT
&Dates;
&get_id;
$transaction_id= "AM" . sprintf("%06d",$id);
$string= chr(02) . "98" . $transaction_id . $fecha . $hora . chr(03) . "\n";
#$string= chr(02) . "98" . $transaction_id . $fecha . $hora . chr(03);
print $sock "$string" or die;
print "REQ: $string\n";
&save_echo ($string);
$response = scalar <$sock>;
print "RES: $response\n";
&save_echo ($response);
sleep(10);
$counter++;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Socket IO now new line
by tachyon-II (Chaplain) on May 07, 2008 at 02:19 UTC | |
|
Re: Socket IO NO new line
by kyle (Abbot) on May 07, 2008 at 02:20 UTC | |
by tachyon-II (Chaplain) on May 07, 2008 at 02:36 UTC | |
by pc88mxer (Vicar) on May 07, 2008 at 02:55 UTC | |
|
Re: Socket IO NO new line
by jasonk (Parson) on May 07, 2008 at 02:36 UTC | |
|
Re: Socket IO NO new line
by locked_user sundialsvc4 (Abbot) on May 07, 2008 at 02:42 UTC |