I added a simple socket perl server script under Cygwin Xinetd to echo client input but it reads blank instead

0

I installed a x32 version 1.7.33 of Cygwin on my x64 Windows7 machine.

I added a new service under /etc/xinetd.d/ccapi.

$ cat ccapi-stream
service ccapi
{
        id = ccapi-stream
        disable = no
        socket_type = stream
        protocol = tcp
        wait = no
        user = alma
        server = /cygdrive/c/ccintegration/scripts/cygwin/server_xinet.exe
        port = 49300
}

I followed the xinetd-README to install xinetd and started it:

cygrunsrv -I xinetd -d "CYGWIN xinetd" -p /usr/sbin/xinetd -a "-stayalive -dontfork" -y tcpip -u alma -w xxx
cygrunsrv -S xinetd

Command "ps -ef" shows xinetd is running.

The server_xinet.exe is a compiled ActiveState perl script. It echoes what it receives from the client:

...
open($localLog ">> local.log");
$rdata = <STDIN>;
chomp($rdata);
print $localLog "  Data Received at $d $t: <$rdata>\n";  # so I know xinetd loads this exe
close $localLog;

# write response data to the connected client
print STDOUT "You said: $rdata\n";
exit;

The client perl script just sends a string to port 49300.

$HOST = "127.0.0.1";  # also tried using hostname "HOST.xxx.com";
$PORT = "49300";
$data = "@ARGV";

$socket = IO::Socket::INET->new(
    PeerAddr => "$HOST",
    PeerPort => "$PORT",
    Proto => "tcp",
    );
die "Could not connect to $HOST:$PORT : $@\n" unless $socket;

  print $socket "$data\n";
  $socket->flush();
  $answer = <$socket>;
  print "Echo from server: <$answer>\n";
close($socket);

I ran this client script on the same machine and it receives nothing from the server

$ perl simpleClient.pl "This is it:"
Echo from server: <>

I checked the local.log and finds a new entry in there:

Data Received at 2015mar12 10:11:39: <>

This means cygwin xinetd launches server_xinet.exe.

The problem is that the server reads nothing from <STDIN> and whatever it writes to <STDOUT>, the client did not receive it.

I ported this from a Unix machine and it works fine there.

What is the problem here in Cygwin?

Thanks for any help you can provide.

Alan Ma

Posted 2015-03-12T16:24:06.973

Reputation: 1

Answers

0

I finally got my client/server talking to each other. I decided to use cygwin perl to run both the server and client and it works. Instead of /cygdrive/c/ccintegration/scripts/cygwin/server_xinet.exe (compiled using ActiveState PDK) in /etc/xinetd.d/ccapi-stream, I replaced it with /cygdrive/c/ccintegration/scripts/cygwin/server_xinet.pl Then use '#!/usr/bin/perl' as the first line in both server_xinet.pl and simpleClient.pl.

./simpleClient.pl "This is working" Echo from server:

Regards, alma

Alma56

Posted 2015-03-12T16:24:06.973

Reputation: 3