socket not sending or receiving data

Discussion in 'Perl' started by anuradha.k.r@sify.com, Feb 24, 2004.

  1. Guest

    hi,
    I 'v e written both the server and client side socket programs in
    perl( a very small one).My socket is created and shows that the
    connection is established with the client.however I am not able to
    receive data in server side.I think the client sends the data
    properly.Somehow receive does not happen.
    Can someone tell me what could be wrong?
    My code is part of the sample programs available for socket prgmng in
    the net.
    Here is the code for both client.

    Client:
    # !;/usr/perl -w

    #client part

    use IO::Socket::INET;
    $sock = new IO::Socket::INET(
    PeerAddr => '130.10.5.76',
    PeerPort => '7070',
    Proto => 'tcp'
    );
    die "could not create client socket: $!\n" unless $sock;

    print "$sock Hello there!\n";

    #send message

    print "enter message to be sent:";

    #while($msg = <STDIN>){
    $msg = <STDIN>;

    chomp $msg;
    if($msg ne ''){
    print "\nsending message\n";
    if($sock->send($msg)){
    print "\ndone\n";
    print $msg;
    }
    else{
    print "message not sent\n";
    }
    }
    close($sock);

    print "socket closed\n";

    #########################################

    Server:


    # !/usr/perl -w
    #socket server

    use IO::Socket::INET;

    #create,bind,listen socket
    $sock = new IO::Socket::INET(
    Localhost => '130.10.5.38',
    LocalPort => '7070',
    Proto => 'tcp',
    Listen => 1,
    Reuse => 1,
    );
    die "Could notcreate socket: $!\n" unless $sock;

    print "socket created\n";
    $new_sock = $sock->accept();


    while(defined(<$new_sock>)) {
    print $_;
    }
    print "$new_sock";

    $msg = "\nReceiving message\n";
    #while(1){

    if($new_sock->recv($text,4)){
    if($text ne ''){
    print "\nMessage received\n";
    print $text;
    }
    else{
    print "\nMessage is null\n";
    print $text;
    }
    }
    else{
    print "\nReceive not success\n";
    }
    #}

    close($sock);
    close ($new_sock);
    print "server socket closed";

    regards & thanx,
    AV
    , Feb 24, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jan Li?e
    Replies:
    6
    Views:
    765
    Steve Horsley
    Feb 8, 2004
  2. riloo
    Replies:
    0
    Views:
    791
    riloo
    Apr 27, 2004
  3. TreatmentPlant
    Replies:
    4
    Views:
    408
    Default User
    Oct 17, 2007
  4. subeen
    Replies:
    2
    Views:
    588
    subeen
    Oct 4, 2009
  5. pintu
    Replies:
    0
    Views:
    202
    pintu
    Dec 14, 2006
Loading...

Share This Page