in reply to Socket recv?

I think send and recv are only for UDP, not for TCP.

For TCP, you can just treat the socket as a filehandle and read and write using print and <> (or readline).

Replies are listed 'Best First'.
Re^2: Socket recv? (!readline)
by tye (Sage) on Mar 12, 2011 at 04:50 UTC

    Please don't encourage people to use <> / readline on sockets. It is a great way to have things appear to lock up mysteriously (just because something arrived that didn't end in a newline character). It is a much better idea to read from a socket using read or sysread.

    - tye        

      read will block until the requested number of characters has arrived (if possible). (Not sure how that's different than readline.) select cannot be used in conjunction with read.

      sysread will block until data is present and return whatever data is present (up to the specified amount). sysread and select can work in concert.

Re^2: Socket recv?
by packetstormer (Monk) on Mar 11, 2011 at 21:00 UTC
    Like this?
    ....... print "\nEnter a string to send to SIP: "; $string=<STDIN>; chomp($string); print $socket $string; #$socket->send($string."\n"); #$socket->recv($data,1024); #print $data; print <$socket>;
    Its the same result!

      I don't know - I would imagine that you will need to look at what gets send over the wire to know what your server responds. Also look at Net::SIP if you're actually doing SIP.

        The SIP is a TLA for the server name not the SIP protocol!!

        I am using strict in my code, I should have posted that too.

        What do you mean checking return values, I thought that is what I am doing print the recv value?

        And I am not sure what you mean by closing the socket. I am not closing the socket, as far as I can see!
Re^2: Socket recv?
by ikegami (Patriarch) on Mar 11, 2011 at 22:06 UTC
    They can be used with TCP, but I don't think there are any benefits to doing so.
Re^2: Socket recv?
by Illuminatus (Curate) on Mar 11, 2011 at 21:48 UTC
    send and recv are calls that can only be used in a connected-state socket (ie TCP).

      You have to use send for unconnected sockets. Saying it can't be used for unconnected sockets is nonsense. The system would have no idea where to send the data to.

      Furthermore, UDP sockets can be connected. Connecting a UDP socket specifies the default host+port for sending, and it specifies the only host+port from which it will receive.