Windows 2000 socket problems

spikemike
spikemike used Ask the Experts™
on
I have written client and server perl scripts for a build process that runs on my machine.  These run fine on both NT and Linux.  However when I put the client script on Windows 2000 with a security template on it, it would not execute.  Both machines could ping each other.  A system administrator here said that Win2K handles sockets differently than NT.  Is this my problem? Or are the security policies messing up my socket connection?  Also there are domain vs workgroups issues, the machine executing the client script was not on the domain.  Here is what I have tested the client script on for debugging purposes:

Machine 1:
Win2K
Security templates installed
Not on domain
Script NOT working

Machine 2:
WinNT
No security installed
Not on domain
Script IS working

Machine 3:
Linux (2.4 kernel)
No clue about security lockdown
On doman
Script IS working

From these it would seem that being on the domain does not matter.  Are there any know issues that I should be aware of?  If Win2K is the problem, how do I resolve this?  Also sorry about the low number of points... if people ever got around to giving me points for questions I solved, I would have more.  Here is the code:

Client:
#!/usr/bin/perl -w
use strict;
use English;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $line, $proj, $ret);

unless (@ARGV == 1) { die "usage: $0 command" }
$proj = $ARGV[0];
$proj = $proj . "\n";
$ret = 1;
$host ="192.168.97.114";
$port = 9000;
 

# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto     => "tcp",
                                PeerAddr  => $host,
                                PeerPort  => $port)
    or die "can't connect to port $port on $host: $!";

print STDERR "[Connected to $host:$port]\n";
if($OSNAME eq "MSWin32") {
   print $handle $proj;
}
else {
   # split the program into two processes, identical twins
   die "can't fork: $!" unless defined($kidpid = fork());


   # the if{} block runs only in the parent process
   if ($kidpid) {
   # copy the socket to standard output
      while (defined ($line = <$handle>)) {
         print STDOUT $line;
         $_ = $line;
         if (/Commands:/) { $ret = 0; }
      }
      kill("TERM", $kidpid);              # send SIGTERM to child
      if ($ret == 0) { die "Build did not run"; }

   }
   # the else{} block runs only in the child process
   else {
      # copy command to the socket
      print $handle $proj;
      print $handle "exit\n";
   }
}


Server:
#!/usr/bin/perl -w
use IO::Socket;
use Net::hostent;            # for OO version of gethostbyaddr
$built = 1;
$PORT = 9000;                  # pick something not in use
$COEDIR = "C:\\COEBuild";

#Set up mapped network drives
system("net use W: \\\\IM114\\COEBuild");
system("net use X: \\\\IM114\\Test");
$server = IO::Socket::INET->new( Proto     => 'tcp',
                                 LocalPort => $PORT,
                                 Listen    => SOMAXCONN,
                                 Reuse     => 1);

die "can't setup server" unless $server;
print "[Server $0 accepting clients]\n";

while ($client = $server->accept()) {
   $client->autoflush(1);
   #print $client "Welcome to COE Build Server\n";
   $hostinfo = gethostbyaddr($client->peeraddr);
   printf "[Connect from %s]\n", $hostinfo->name || $client->peerhost;
   while ( <$client> ) {
      next unless /\S/;           # blank line
      print $_;
      if (/quit|exit/i) {
         last;
      }
      elsif (/immaccs/i) {
         system("$COEDIR\\Immaccs\\Build.bat");
      }
      elsif (/seaway/i ) {
         system("$COEDIR\\Seaway\\Build.bat");
      }
      elsif (/sils/i ) {
         system("$COEDIR\\Sils\\Build.bat");
      }
      elsif (/test/i ) {
         system("$COEDIR\\Test\\Build.bat");
      }
      elsif (/icdm/i ) {
         system("$COEDIR\\Icdm\\Build.bat");
      }
      else {
         print $client "Commands: immaccs seaway sils test icdm\n";
         $built = 0;
      }
   #} continue {
      if($built == 1) { print $client "Build successful \n"; }
    #  print $client "Command? \n";
   }
   print $client "Goodbye\n";
   printf "[Client Disconnected]\n";
   close $client;
}  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Commented:
The problem is that you use the print() function to send data to the socket(e.g."print $handle $proj;"). This doesn't work on all systems. So you should use '$handle->send($proj)' instead. For reading from sockets you can use '$handle->recv($buf,$length)'.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept a comment by jlell

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

inq123
EE Cleanup Volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial