[prev in list] [next in list] [prev in thread] [next in thread]
List: perl-beginners
Subject: Re: IO::Socket operations
From: Shlomi Fish <shlomif () iglu ! org ! il>
Date: 2010-09-28 9:31:26
Message-ID: 201009281131.26761.shlomif () iglu ! org ! il
[Download RAW message or body]
Hi Anand,
On Tuesday 28 September 2010 06:52:26 Anand Parthiban wrote:
> Dear Team,
>
> I am a newbie to PERL,
See http://perl.org.il/misc.html#pl_vs_pl .
>
> I was studying about the Socket programming in perl and I was Doing a
> Sample Programs using IO::Socket
>
> I have Written a Sample Server Client program and it works great,
>
> Now, the Problem is that the server is able to listen on Some ports and
> when the client sends any message,
>
> the server is able to Print the message and exiting , But what i want is
> that the server should able to listen continuosly
>
> after printing that message.
>
> Can Anyone help me how to do this
>
> Thanks in Advance
>
>
>
> THIS IS SERVER PROGRAM
> ###################################
> #!/usr/bin/perl
Add "use strict;" and "use warnings;". See:
http://perl-begin.org/tutorials/bad-elements/
for more information.
> use IO::Socket;
> my $sock = new IO::Socket::INET (
This should be IO::Socket::INET->new(
> LocalHost => '192.168.0.217',
> LocalPort => '3890',
> Proto => 'tcp',
> Listen => 1,
> Reuse => 1,
> );
Your code needs indentation and empty lines between paragraphs.
> die "Could not create socket: $!\n" unless $sock;
> my $new_sock = $sock->accept();
> while(<$new_sock>) {
> print $_;
> }
> close($sock);
I believe you're accepting one connection (which blocks further connections),
handling it, and afterwards exiting from the program. If you want to handle
one connection at a time you can do while (my $new_sock = $sock->accept()) {
... }. If you wish to handle several simultaneous connections, look at POE,
IO::Async, AnyEvent, IO::Lambda,.... Reflex on the CPAN.
Regards,
Shlomi Fish
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
"Star Trek: We, the Living Dead" - http://shlom.in/st-wtld
<rindolf> She's a hot chick. But she smokes.
<go|dfish> She can smoke as long as she's smokin'.
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org
http://learn.perl.org/
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic