0
#!/usr/bin/perl -w 

use strict;
use warnings;

sub nap {
    sleep 1;
    }

        use IO::Socket; 
        use Net::hostent;              # for OO version of gethostbyaddr 
    my $PORT = 9000;




        my $server = IO::Socket::INET->new(
                                 LocalAddr => 'localhost',
                                 LocalPort => $PORT,
                                 Proto     => 'tcp') or die ("error connection\n");

        
        
        

    print "SERVER Waiting for client connection on port $PORT\n";

         while ( $server->sockname()) {
             
          $server->autoflush(1);
      print $server, "Welcome. Sim is ready.\r\n";
         ≉##Waiting    

print $server, "enter details\r\n\n";    
≉    ##waiting    
my $nrecord = <>;        
chomp $nrecord;    
&nap;##Waiting    
        
(my $Record,my $Priority, my $Location,my $filename,my $time)= split(m/ /,$nrecord); 
print $server ,"this is usr input: $nrecord\r\n";
    
&nap;##Waiting        
print  $server, "This is priority $Priority\r\n";    
&nap;##waiting    
print $server,"This is Location $Location\r\n";

}

Just run this code.

Happy man ;)

Edited by richieking: n/a

0

Restart your Activeperl before you run the code ok?

This is working 100%.

I can post a screenshot if you want. ;)

0

Screen shot brother.

SERVER Waiting for client connection on port 9000
IO::Socket::INET=GLOB(0x87c3b98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x87c3b98)enter details
0

more screen shot

SERVER Waiting for client connection on port 9000
IO::Socket::INET=GLOB(0x87c3b98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x87c3b98)enter details

wwwww nnnnn kkkkk lllll iiiii

IO::Socket::INET=GLOB(0x87c3b98)this is usr input: wwwww nnnnn kkkkk lllll iiiii

IO::Socket::INET=GLOB(0x87c3b98)This is priority nnnnn
IO::Socket::INET=GLOB(0x87c3b98)This is Location kkkkk
IO::Socket::INET=GLOB(0x87c3b98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x87c3b98)enter details

SERVER Waiting for client connection on port 9000
IO::Socket::INET=GLOB(0x88adb98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x88adb98)enter details

The king Jesus 4333 Kingdom
IO::Socket::INET=GLOB(0x88adb98)this is usr input: The king Jesus 4333 Kingdom
IO::Socket::INET=GLOB(0x88adb98)This is priority king
IO::Socket::INET=GLOB(0x88adb98)This is Location Jesus
IO::Socket::INET=GLOB(0x88adb98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x88adb98)enter details

Ithink I love this perl
IO::Socket::INET=GLOB(0x88adb98)this is usr input: Ithink I love this perl
IO::Socket::INET=GLOB(0x88adb98)This is priority I
IO::Socket::INET=GLOB(0x88adb98)This is Location love
IO::Socket::INET=GLOB(0x88adb98)Welcome. Sim is ready.
IO::Socket::INET=GLOB(0x88adb98)enter details

Hope you are happy now. ;)

Edited by richieking: n/a

0

the program suppose to listen port and it should connect via telnet.

so it should be like: perl myscript.pl
it should display like below:
SERVER Waiting for client connection on port 9000

Then, another command window,
telnet localhoat 9000
here it connets.

on this window (telnet), user enter the command and it should disply or print on this window.

sorry for misunderstanding. My previous code was connecting via telnet, but when i enter any command, it doesn't do anything. It just sit there.

so, I need to figure it why it's not printing on that window. I tried your code and it works really well on same window, but we need to connect port via telnet and everything needs to be done on telnet window.

0

Here is how program should work:
the program suppose to listen port and it should connect via telnet.

so it should be like: perl myscript.pl
it should display like below:
SERVER Waiting for client connection on port 9000

Then, another command window,
telnet localhoat 9000
here it connets
Same window, User enter command: Record 29 Newyork myfile 34
it should print:
Priority - 29
Location - Newyork

Anywaz, I wrote a client script and used code that you suggested and worked fine. so instead of "telnet localhost 9000", I used client script.

it should be like: perl myscript.pl
it should display like below:
SERVER Waiting for client connection on port 9000

perl myclient.pl - connection sucessful.
Same window, User enter command: Record 29 Newyork myfile 34
it should print:
Priority - 29
Location - Newyork


Thanks for all your help.
I really appreciated your help and time.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.