perl tcp server script works, but no data.

Discussion in 'Perl Misc' started by Eli Sidwell, May 19, 2004.

  1. Eli Sidwell

    Eli Sidwell Guest

    I am trying to get the following script to accept data, but I never see any.
    Is this a flushing issue ?

    Any help is appreciated.


    #!/usr/bin/perl -w

    $server_port = "5001";

    use IO::Socket;

    # make the socket
    $server = IO::Socket::INET->new(LocalPort => $server_port,
    Type => SOCK_STREAM,
    Proto => 'tcp',
    Reuse => 1,
    Listen => 10 ) # or SOMAXCONN
    or die "Couldn't be a tcp server on port $server_port : $@\n";

    $server->autoflush();

    while ($client = $server->accept()) {
    # $client is the new connection

    $client->recv($str, 1024)
    or die "Can't recv: $!\n";

    $client_ip = $client->peerhost;
    $client_port = $client->peerport;

    print "Data is: $str \n";
    print "Client IP: $client_ip\n";
    print "Client port: $client_port\n";
    }

    close($server);
     
    Eli Sidwell, May 19, 2004
    #1
    1. Advertising

  2. Eli Sidwell

    Eli Sidwell Guest

    Still nothing, the $nread even comes up 0.

    As far as the client, I tried to telnet a small file to that port and
    then I wrote an app using the VB winsock to move text to that port.
    Both times it opens the port and accepts the data (I think), I can get
    the port and IP from perl but, I don't see any data.

    Are there any good reference books on the perl socket with examples.
    I have the orilly cookbook, but its a lot of theory.

    Thanks



    Jim Gibson <> wrote in message news:<190520041320228983%>...
    > In article <>, Eli
    > Sidwell <> wrote:
    >
    > > I am trying to get the following script to accept data, but I never see any.
    > > Is this a flushing issue ?
    > >
    > > Any help is appreciated.
    > >
    > >
    > > #!/usr/bin/perl -w
    > >
    > > $server_port = "5001";
    > >
    > > use IO::Socket;
    > >
    > > # make the socket
    > > $server = IO::Socket::INET->new(LocalPort => $server_port,
    > > Type => SOCK_STREAM,
    > > Proto => 'tcp',
    > > Reuse => 1,
    > > Listen => 10 ) # or SOMAXCONN
    > > or die "Couldn't be a tcp server on port $server_port : $@\n";
    > >
    > > $server->autoflush();
    > >
    > > while ($client = $server->accept()) {
    > > # $client is the new connection
    > >
    > > $client->recv($str, 1024)
    > > or die "Can't recv: $!\n";

    >
    > recv() is for UDP messages. You have specified a TCP connection. Try
    >
    > my $nread = $client->read($str,1024);
    > die "Can't read from socket: $!" unless defined $nread;
    >
    > instead.
    >
    > >
    > > $client_ip = $client->peerhost;
    > > $client_port = $client->peerport;
    > >
    > > print "Data is: $str \n";
    > > print "Client IP: $client_ip\n";
    > > print "Client port: $client_port\n";
    > > }
    > >
    > > close($server);

    >
    > You have not shown the client program, so there could be a problem
    > there as well.
     
    Eli Sidwell, May 20, 2004
    #2
    1. Advertising

  3. In article <>, Eli Sidwell
    wrote:

    Please, no top posting...

    > Still nothing, the $nread even comes up 0.
    >
    > As far as the client, I tried to telnet a small file to that port and
    > then I wrote an app using the VB winsock to move text to that port.
    > Both times it opens the port and accepts the data (I think), I can get
    > the port and IP from perl but, I don't see any data.
    >
    > Are there any good reference books on the perl socket with examples.
    > I have the orilly cookbook, but its a lot of theory.
    >

    -snip-

    perldoc 'perlipc' has a basic TCP client/server that I have used as the basis
    for a couple of different things. Its not too complex.

    Kevin
     
    Kevin Collins, May 21, 2004
    #3
  4. Eli Sidwell

    Anno Siegel Guest

    Kevin Collins <> wrote in comp.lang.perl.misc:
    > In article <>, Eli Sidwell
    > wrote:
    >
    > Please, no top posting...
    >
    > > Still nothing, the $nread even comes up 0.
    > >
    > > As far as the client, I tried to telnet a small file to that port and
    > > then I wrote an app using the VB winsock to move text to that port.
    > > Both times it opens the port and accepts the data (I think), I can get
    > > the port and IP from perl but, I don't see any data.
    > >
    > > Are there any good reference books on the perl socket with examples.
    > > I have the orilly cookbook, but its a lot of theory.
    > >

    > -snip-
    >
    > perldoc 'perlipc' has a basic TCP client/server that I have used as the basis
    > for a couple of different things. Its not too complex.


    There's also Net::EasyTCP which covers simple TCP-based client/server
    pairs.

    Anno
     
    Anno Siegel, May 21, 2004
    #4
  5. Eli Sidwell

    Eli Sidwell Guest

    -berlin.de (Anno Siegel) wrote in message news:<c8kgsg$smk$-Berlin.DE>...
    > Kevin Collins <> wrote in comp.lang.perl.misc:
    > > In article <>, Eli Sidwell
    > > wrote:
    > >
    > > Please, no top posting...
    > >
    > > > Still nothing, the $nread even comes up 0.
    > > >
    > > > As far as the client, I tried to telnet a small file to that port and
    > > > then I wrote an app using the VB winsock to move text to that port.
    > > > Both times it opens the port and accepts the data (I think), I can get
    > > > the port and IP from perl but, I don't see any data.
    > > >
    > > > Are there any good reference books on the perl socket with examples.
    > > > I have the orilly cookbook, but its a lot of theory.
    > > >

    > > -snip-
    > >
    > > perldoc 'perlipc' has a basic TCP client/server that I have used as the basis
    > > for a couple of different things. Its not too complex.

    >
    > There's also Net::EasyTCP which covers simple TCP-based client/server
    > pairs.
    >
    > Anno


    I think that I have narrowed the problem, it seems that I don't
    receive any data unless I send more than a 2k of stuff. I have seen
    some postings that refer to flushing issues, how do I cause this code
    to flush no matter what size data is received?

    Thanks
     
    Eli Sidwell, May 22, 2004
    #5
  6. Eli Sidwell

    Ben Morrow Guest

    Quoth (Eli Sidwell):
    > I think that I have narrowed the problem, it seems that I don't
    > receive any data unless I send more than a 2k of stuff. I have seen
    > some postings that refer to flushing issues, how do I cause this code
    > to flush no matter what size data is received?


    This sounds like a problem on the sending end... you need to flush after
    each write. In perl, set $|=1.

    Ben

    --
    Outside of a dog, a book is a man's best friend.
    Inside of a dog, it's too dark to read.
    Groucho Marx
     
    Ben Morrow, May 22, 2004
    #6
    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. dpackwood
    Replies:
    3
    Views:
    1,824
  2. Johann Blake
    Replies:
    1
    Views:
    1,211
    Hermit Dave
    Jan 5, 2004
  3. F. GEIGER
    Replies:
    3
    Views:
    782
    F. GEIGER
    Aug 6, 2004
  4. Tiger
    Replies:
    5
    Views:
    977
    Dave Thompson
    May 1, 2006
  5. Aaron Johnson
    Replies:
    0
    Views:
    176
    Aaron Johnson
    Nov 2, 2005
Loading...

Share This Page