iKnowNothing has asked for the wisdom of the Perl Monks concerning the following question:

Hello perl monks, please enlighten me. I am new to programming socket connections, but I have been tasked with a project in which I need a couple computers to communicate. I have had success getting my scripts to work using the "send" and "read" functions on the socket handle. The only problem is that I have no idea what the "flags" input to the send function does. I have it set to 1 for now, and all that I know is that it works this way. Please tell me, what are the flags?

2004-11-03 Edited by Arunbear: Changed title from 'question about send', as per Monastery guidelines

Replies are listed 'Best First'.
Re: 'flags' parameter of socket send()
by superfrink (Curate) on Nov 02, 2004 at 01:58 UTC
    First type send in the search box at the top of perlmonks (or run " perldoc -f send "). Normally we get the docs for a function this way. Interestingly the flags are not mentioned but we see that it says:
    Takes the same flags as the system call of the same name.
    Now I'm going to assume you're not used to programming in a unix-like system environment so the unix man pages can be accessed like " man send " (it actually varies depending on your system). (A "man page" is part of the system manual and each "page" describes a part of the system, often a command or function call.) If I don't have the man page on my system I often just google for it like: man send. The first hit is often what I'm looking for.

    I hope that should help a bit. Best regards, Chad
      Thanks.. it didn't even occur to me to search for the unix function (I'm doing development under windows after all...) So my next question is, does the flags input mean anything when the script is running in windows?
Re: 'flags' parameter of socket send()
by pg (Canon) on Nov 02, 2004 at 02:45 UTC

    The flag is the bit OR of several valid values. For example, the flag can be set to MSG_PEEK, if you use that value with recv, recv() will only peek at the buffer, but will not remove data from the buffer:

    use IO::Socket::INET; use strict; use warnings; my $s = IO::Socket::INET->new(Proto=>"tcp", PeerAddr => "www.yahoo.com +", PeerPort => 80); print $s "GET / HTTP/1.1\r\nHost: www.yahoo.com\r\n\r\n"; my $foo; for (1..5) { recv $s, $foo, 15, MSG_PEEK; print "========\n"; print $foo; print "\n"; }

    If you run the above code, you will keep getting the first 15 bytes of the response:

    ======== HTTP/1.1 200 OK ======== HTTP/1.1 200 OK ======== HTTP/1.1 200 OK ======== HTTP/1.1 200 OK ======== HTTP/1.1 200 OK