how can I send messages from both sides through socket?

Discussion in 'Perl Misc' started by B. W., May 20, 2004.

  1. B. W.

    B. W. Guest

    I want to send a request from A to B through socket, then B returns the
    process result back to A for display. I run B script first then start A
    script, but I got error message at B side "can't use an undefined value as a
    symbol reference at line 'print $sock_send "$result";'. How can I have both
    sides to support sending messages?

    the script I created is as:

    A side script:
    use IO::Socket;
    my $sock_recv = new IO::Socket::INET(Localhost
    =>'localhost';

    LocalPort =>'7071',

    Proto =>'tcp',

    Listen =>1,

    Reuse =>1,

    Timeout =>20,
    );
    die "error create receive socket" unless $sock_recv;

    $sock_send = new IO::Socket::INET( PeerAddr
    =>'localhost',

    PeerPort =>'7070',

    Proto =>'tcp',
    );
    die "error create send socket" unless $sock_send;

    print $sock_send "$request";

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

    close ($sock_send);
    close ($sock_recv);

    B side script:
    use IO::Socket;
    my $sock_recv = new IO::Socket::INET(Localhost
    =>'localhost';

    LocalPort =>'7070',

    Proto =>'tcp',

    Listen =>1,

    Reuse =>1,

    Timeout =>20,
    );
    die "error create receive socket" unless $sock_recv;

    $new_sock = $sock_recv->accept();
    while (defined ($buf = <$new_sock>)) {
    $sock_send = new IO::Socket::INET( PeerAddr
    =>'localhost',

    PeerPort =>'7070',

    Proto =>'tcp',
    );
    die "error create send socket" unless $sock_send;

    $result = <some lines to get result from received
    $buf>;
    print $sock_send "$buf";
    close ($sock_send);
    }
    close ($sock_recv);


    thanks,
    B.W.
    B. W., May 20, 2004
    #1
    1. Advertising

  2. "B. W." <> wrote in
    news:x32rc.69143$:

    > I want to send a request from A to B through socket, then B returns
    > the process result back to A for display. I run B script first then
    > start A script, but I got error message at B side "can't use an
    > undefined value as a symbol reference at line 'print $sock_send
    > "$result";'. How can I have both sides to support sending messages?
    >
    > the script I created is as:
    >
    > A side script:
    > use IO::Socket;
    > my $sock_recv = new IO::Socket::INET(Localhost
    > =>'localhost';
    >
    > LocalPort =>'7071',
    >
    > Proto =>'tcp',
    >
    > Listen =>1,


    You might want to spend some time properly formatting your code for
    others to want to read it.

    When one side is done sending, it should tell the other side it is done
    sending:

    perldoc -f shutdown.

    --
    A. Sinan Unur
    (reverse each component for email address)
    A. Sinan Unur, May 20, 2004
    #2
    1. Advertising

  3. B. W.

    Eric Bohlman Guest

    "B. W." <> wrote in
    news:x32rc.69143$:

    > I want to send a request from A to B through socket, then B returns
    > the process result back to A for display. I run B script first then
    > start A script, but I got error message at B side "can't use an
    > undefined value as a symbol reference at line 'print $sock_send
    > "$result";'. How can I have both sides to support sending messages?
    >
    > the script I created is as:
    >
    > A side script:
    > use IO::Socket;


    No 'use strict'.
    No 'use warnings'.

    Let perl find as many of your problems as it can.

    > my $sock_recv = new IO::Socket::INET(Localhost
    > =>'localhost';


    That semicolon should be a comma. Given that I see this in two different
    places in your code, and that nowhere does your code contain the
    actual statement that you claim gives the error message, I can only
    conclude that the code you posted resembles, but is not identical to, the
    code you're actually trying to run. Posting mutant code is a Bad Thing;
    all it accomplishes is wasting everyone's time. None of us here, AFAIK,
    have the psychic powers they'd need in order to determine what your actual
    code is from what you've posted.

    Try again (*after* enabling warnings and strictures and correcting anything
    that perl complains about when you do), but this time *copy and paste* the
    *exact* code that's giving you the problem. Not something "like" it, but
    the Real Thing. Post something that any of us can copy from our
    newsreaders and run without having to alter it. Otherwise the people who
    know what they're talking about will refuse to engage in futile guesswork,
    and any responses you'll get will be likely to come from people who may not
    really know what they're talking about.
    Eric Bohlman, May 20, 2004
    #3
    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. Bryan
    Replies:
    1
    Views:
    426
  2. HP
    Replies:
    3
    Views:
    409
    Ben C
    Mar 9, 2007
  3. Water Lin
    Replies:
    6
    Views:
    926
    James Kanze
    Jun 3, 2009
  4. H
    Replies:
    2
    Views:
    90
  5. Reply Via Newsgroup

    How can I trim the sides of a string?

    Reply Via Newsgroup, Apr 5, 2004, in forum: Javascript
    Replies:
    11
    Views:
    195
Loading...

Share This Page