Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

It works for me (and quite impressively too++). Maybe you are not running a proper OS?

It is worth checking if number of open files or number of simultaneous connections at server is exceeded.

Anyway, here is a client I whipped up to test your server:

#!/usr/bin/perl -w # Program to connect to a server (set HOST and PORT below) # and send some commands to it randomly chosen from the # list of commands (see @COMMANDS below) with some # arguments if randomly decided. # After sending each command it displays output received # and then sleeps for some random time specified by # the command line options: commands-per-second-min and -max # When 'time-to-live' seconds have elapsed (more or less) # the client shuts down. # # Usage: client.pl TTL cps-min cps-max # TTL: will shutdown in TTL seconds more or less # cps-min, cps-max: send bettwen cps-min and cps-max # commands (request) per second to the server. # # Author: bliako # 28/09/2018 # for https://perlmonks.org/?parent=1223158;node_id=3333 # use strict; use warnings; use Net::Telnet; use Time::HiRes; my @COMMANDS = qw/PING HELLO/; my ($HOST, $PORT) = ('127.0.0.1', '1337'); if( scalar(@ARGV) != 3 ){ print STDERR "Usage : $0 time-to-live comman +ds-per-second-min commands-per-second-max\n"; exit(1) } my ($ttl, $cps_min, $cps_max) = @ARGV; my @queue = (); my $attl = $ttl; # calculate seconds between commands (can be fractional and less than +1) # cps: commands-per-second # spc: seconds-between-commands my ($spc_min, $spc_max) = sort (1.0/$cps_min, 1.0/$cps_max); while($attl > 0 ){ # calculate sleep time before running this command my $rsbc = $spc_min + rand($spc_max-$spc_min); # get a random command my $cmd = $COMMANDS[int(rand(scalar(@COMMANDS)))]; if( rand() < 0.5 ){ # add optional args to command randomly $cmd .= " optional-argument=".int(rand(100000)); } # add command and sleep time to queue push @queue, [$cmd, $rsbc]; # reduce time-to-live $attl -= $rsbc; } # end the session push @queue, ['QUIT 123', $spc_min]; my $num_cmds = scalar(@queue); print "$0 : here is the list of comamnds and sleep times to send to se +rver:\n"; print $_->[0].' and sleep for '.$_->[1]." s\n" for @queue; my $tel = Net::Telnet->new( Host => $HOST, Port => $PORT ) or die "telnet new failed for ${HOST}:${PORT}"; $tel->open() or die "telnet open() failed, $!"; # important to set the prompt correctly # otherwise you may get 'pattern match read eof' # see also https://www.perlmonks.org/?node_id=672565 $tel->prompt('/>/') or die "telnet prompt() failed, $!"; my $time_started = time; print "$0 : starting...\n"; foreach (@queue){ my ($cmd, $rsbc) = @$_; print "$0 : sending command '$cmd' ... \n"; my @lines = $tel->cmd($cmd); print "$0 : data received:\n".join("\n", @lines)."\n--- end da +ta received.\n"; print "$0 : sleeping for $rsbc s ...\n"; Time::HiRes::sleep($rsbc); } print "$0 : shutting down ...\n"; $tel->close() or die "close(), $!"; print "$0 : done send $num_cmds commands in ".(time-$time_started)." s +.\n"; exit(0);

Use it like so: client.pl 10 1 2 for sending between 1 and 2 commands per second over a total of 10 seconds to the server.

If you want to test multiple simultaneous client connections do this:

for i in `seq 1 2`; do (./client.pl 10 1 2; st=$?; if [ $st -ne 0 ]; then echo "FAILED with $st"; fi) & done

Replace seq 1 2 to seq 1 1000 to test 1000 clients simultaneously and see if your OS can handle that.

bw, bliako


In reply to Re: Client-Server app by bliako
in thread Client-Server app by radu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others cooling their heels in the Monastery: (4)
    As of 2020-10-29 02:42 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (266 votes). Check out past polls.

      Notices?