I want to use this server framework for a project of mine, but somehow when a client connects to it using telnet or something similar, the server just sits there and waits for the user to type any button, before sending that which he was supposed to send right away. I tried to set autoflush to 1, but that didnt seem to work either. Can anyone explain to me, what iam doing wrong? Thanks in advance!
#taken from perlnet
#!/usr/bin/perl
use IO::Socket;
# include the select package
use IO::Select;
# they're counting the number of connections $nconnections_old = 0;
$nconnections_new = 0;
$port = 1234;
$new_client = IO::Socket::INET->new(Proto=>"tcp", LocalPort=>$port, Li
+sten=>$max_clients, Reuse=>1);
# create a new selection and add our basic socket for incoming connect
+ions
$sel = IO::Select->new($new_client);
while (@ready = $sel->can_read) {
# for every readable socket
foreach $client (@ready) {
# check if it is the basic socket
if ($client == $new_client) {
# if it is establish new connection
$add = $client->accept;
# add new socket to the selection
$sel->add($add);
# increase number of connections
$nconnections_new++;
# if it is an already established connectection
} else {
#It waits for user input here, like an enter, or somehing before it pr
+ints the string in $hey to the client.. Why??
$hey="Hey, Iam the server, how are you?";
syswrite($client, $hey, length($hey));
}
}
# if number of connections has changed, print it
if ($nconnections_old != $nconnections_new) {
print "Already $nconnections_new connection(s)\n";
$nconnections_old++;
}
}
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, details, 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, summary, 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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.