How to receive data from a socket

Discussion in 'Perl Misc' started by Suk, Mar 29, 2006.

  1. Suk

    Suk Guest

    Hi

    Im new to perl socket programming.

    I have a server program on a certain machine which simply cat's a file
    when it receives a connection to port 10000 . This is done via inetd on
    a Solaris system as follows:

    Line in /etc/inetd.conf:

    # Test program
    test stream tcp nowait root /usr/bin/test1

    Line from /etc/services:

    # Test program on port 10000
    test 10001/tcp

    The script /usr/bin/test1 simply contains a single line to cat a
    certain text file, so if you telnet to port 10000 you simply get the
    contents of the file.

    I want to write a very simple perl script to connect to this server and
    receive the data into $data
    Problem is that the contents of the file can be very large (>300K) and
    i dont seem to be getting all the data into $data

    Im doing something like this:

    our $sock = new IO::Socket::INET ( PeerAddr => $MESSAGE_SERVER,
    PeerPort => $TARGET_PORT, Proto => 'tcp',);

    And then receiving the data like this:

    recv($sock,$data,3000,0);

    $data doesnt contain everything though.


    Like I say, i've never really done any socket programming before, so if
    if someone knows the correct way of receiving data then that woulbe be
    appreciated.
     
    Suk, Mar 29, 2006
    #1
    1. Advertising

  2. Suk

    Suk Guest

    Thanks very much, that worked perfectly :)
     
    Suk, Mar 30, 2006
    #2
    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. kanchan
    Replies:
    1
    Views:
    834
    Karthik Kumar
    Nov 13, 2004
  2. Replies:
    9
    Views:
    396
    Gabriel Genellina
    Apr 29, 2008
  3. Laszlo Nagy
    Replies:
    1
    Views:
    4,924
    Mark Wooding
    Jan 27, 2009
  4. twgray
    Replies:
    15
    Views:
    3,457
  5. Kamaljeet Saini
    Replies:
    10
    Views:
    234
    Brian Candler
    Jan 26, 2009
Loading...

Share This Page