Ask a Question related to PERL Miscellaneous, Design and Development.

  1. #1

    Default Socket troubles

    Hi,

    I am trying to create two sender and listener sockets using perl.

    ***************
    Listener.pl
    ***************

    #! /usr/bin/perl

    use IO::Socket;
    $sock = new IO::Socket::INET ( LocalHost => 'localhost',
    Local Port => 1200,
    Proto = 'tcp',
    Listen = 5,
    Reuse = 1);

    die "Socket could not be created. Reason: $!" unless $sock;

    while ( $new_sock = $sock->accept() ) {
    while (defined ($buf = <$sock>)) {
    print $buf;
    }
    }

    close ($sock)

    ***********************
    Sender.pl
    ***********************

    #! /usr/bin/perl

    use IO::Socket;
    $sock = new IO::Socket::INET ( PeerAddr => 'localhost',
    PeerPort => 1200,
    Proto = 'tcp',
    );

    die "Socket could not be created. Reason: $!" unless $sock;

    foreach (1 .. 10) {
    print $sock "Msg $_: How are you? \n";
    }

    close ($sock)

    ***********************

    When run the Listener, it waits for new connections, but when I run the
    sender.pl, it just finishes without any output at the listener. I get no
    error messages.

    Any ideas on whats happening?

    Thanks
    harsha

    when I run hostname on my computer, it returns localhost.localdomain. I am
    running both the sender and the listener on my computer. I am using Perl
    5.8.0




    Harshavardhan Guest

  2. Similar Questions and Discussions

    1. MS-SQL troubles
      I have a user who needs access to my SQL server. He can ping the server, but he cannot setup an ODBC connection. I am using SQL authentication and I...
    2. FTP Troubles
      If you are using version 2002 it does not default to index. Versions 2002 and 2003 name the home page according to what you enter for a file name...
    3. Socket.accept problem via Socket.for_fd($stdin.fileno)
      Hi, I am experiencing a rather infuriating problem with Socket.accept on Windows XP. The problem exists when I try to create a Socket from...
    4. Distinguishing between socket buffer full & socket disconnected
      I am using the IO::Select method can_write() to flow control the writing of a large amount of data to a socket, where the writer may well run ahead...
    5. css troubles
      Pardon my ignorance.... I'm really new at this stuff. I'm trying to take some text on my webpage (I didn't create it... someone else did in DMX...
  3. #2

    Default Re: Socket troubles

    -----BEGIN PGP SIGNED MESSAGE-----
    Hash: SHA1

    Harshavardhan wrote:
    > Hi,
    >
    > I am trying to create two sender and listener sockets using perl.
    >
    > ***************
    > Listener.pl
    > ***************
    >
    > #! /usr/bin/perl
    >
    > use IO::Socket;
    > $sock = new IO::Socket::INET ( LocalHost => 'localhost',
    > Local Port => 1200,
    ^^^^^^^^^^
    This is not syntatically-correct code
    > Proto = 'tcp',
    ^^^
    This is an illegal modification of a constant, again not syntatically-correct.
    > Listen = 5,
    ^^^
    So is this one.
    > Reuse = 1);
    ^^^
    And this one.

    Do NOT re-type Perl code when posting to usenet. Use copy+paste or your newsreader's "import" function.

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.1 (GNU/Linux)
    Comment: Using GnuPG with Mozilla - [url]http://enigmail.mozdev.org[/url]

    iD8DBQE/Z8HIeS99pGMif6wRAkyeAJ9y5BH/bSkOAmCuVBwdvH5qG/jkygCglxck
    wYUhYEqCrcMkrmL/InDLI6o=
    =E+CH
    -----END PGP SIGNATURE-----

    Mina Naguib Guest

  4. #3

    Default Re: Socket troubles

    I hate to sound like everyone else in this newsgroup, but if you're not
    using

    use strict;
    use warnings;


    you will be developing in the dark.

    Best of luck,

    Moose
    mooseshoes Guest

  5. #4

    Default Re: Socket troubles

    Thanks guys.

    After I used

    use strict;
    use warnings;

    and after specifying each variable with its package name I found out the
    error and now my program is working. Next time I post I will remember to
    cut and paste the code.

    Thanks for all your help
    harsha


    "mooseshoes" <mooseshoes@gmx.net> wrote in message
    news:fyR9b.90$qm2.55@newssvr27.news.prodigy.com...
    > I hate to sound like everyone else in this newsgroup, but if you're not
    > using
    >
    > use strict;
    > use warnings;
    >
    >
    > you will be developing in the dark.
    >
    > Best of luck,
    >
    > Moose

    Harshavardhan Guest

  6. #5

    Default Re: Socket troubles

    >>>>> "H" == Harshavardhan <hvardhan@ee.duke.edu> writes:

    H> After I used

    H> use strict;
    H> use warnings;

    H> and after specifying each variable with its package name I found out the
    H> error and now my program is working. Next time I post I will remember to
    H> cut and paste the code.

    first off, don't top post.

    secondly, that is the wrong way to work with strict. the correct way is
    to use my. what you did is create package globals and that is not good
    practice.

    uri

    --
    Uri Guttman ------ [email]uri@stemsystems.com[/email] -------- [url]http://www.stemsystems.com[/url]
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- [url]http://jobs.perl.org[/url]
    Damian Conway Class in Boston - Sept 2003 -- [url]http://www.stemsystems.com/class[/url]
    Uri Guttman Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139