FAQ
Dear Team,

I am a newbie to PERL,

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
use IO::Socket;
my $sock = new IO::Socket::INET (
LocalHost => '192.168.0.217',
LocalPort => '3890',
Proto => 'tcp',
Listen => 1,
Reuse => 1,
);
die "Could not create socket: $!\n" unless $sock;
my $new_sock = $sock->accept();
while(<$new_sock>) {
print $_;
}
close($sock);
#######################################
--
*Anand *

Search Discussions

  • Jeff Pang at Sep 28, 2010 at 9:02 am

    2010/9/28 Anand Parthiban <h3lloanand@gmail.com>:


    my $new_sock = $sock->accept();
    while(<$new_sock>) {
    print $_;
    }
    close($sock);
    #######################################
    --

    Put them in a forever loop, like:

    while(1) {
    my $conn = $sock->accept();
    print <$conn>;
    }

    etc.
    You may want to buy the book "Network Programming with Perl" for any
    detail about socket programming.


    Jeff.
  • Shlomi Fish at Sep 28, 2010 at 9:32 am
    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 .
  • Siva at Sep 28, 2010 at 1:06 pm
    Hi All,

    I am new to XML::RPC. I wanted to consume few methods using xm RPC.

    I have my Server at http://localhost:8900. I have a method "login" which
    takes "username,password category" as arguments.I did the following.

    ######### SNIP
    use strict;
    use warnings;
    require RPC::XML;
    require RPC::XML::Client;


    my $cli = RPC::XML::Client->new('http://localhost:8900');
    my $resp=$cli->send_request('system.login(\'test\', \'test\', \'test\')');
    foreach(keys %$resp)
    {
    print "$_ is $$resp{$_}\n";

    }

    ######### SNIP

    I get the following error

    ## ERROR
    faultString is RPC::XML::string=SCALAR(0x1874d94)
    faultCode is RPC::XML::i4=SCALAR(0x1ff11bc)

    ###

    Hwo can i aceess method login wiht XML::RPC::CLient.

    Can somebody help me please.

    THanks,
    Siva

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedSep 28, '10 at 4:52a
activeSep 28, '10 at 1:06p
posts4
users4
websiteperl.org

People

Translate

site design / logo © 2021 Grokbase