Before We look at a little code, if you like would to learn about BSD style sockets in depth then beg, borrow, steal or buy Richard Stevens TCPIP Illustrated series. Expensive but worth every penny. If you would prefer your networking depth served up as Perl; I have recently bought Lincoln Steins 'Networking Programming with Perl' and highly recommend it.

Now here's a little code taken from Lincoln's book. the comments are my own. It is a fragment from a simple daytime client

use Socket; # declare some self describing constants use constant DEFAULT_ADDR => '127.0.0.1'; # the local host use contant PORT => 13; # well known daytime service port use constant IPPROTO_TCP => 6; # lets use TCP shall we # get host from commandline or use default my $address = shift || DEFAULT_ADDR; # well IP address is really a 32bit UINT my $packed_addr = inet_aton($address); # whoops better include socket/port my $destination = sockaddr_in(PORT, $packed_addr); #ok lets put it together get ourselfs a SOKET handle socket(SOCK,PF_INET, SOCK_STREAM, IPPROTO_TCP) or die; # hey man whats the time connect(SOCK, $destination); print <SOCK>; # ## there is a lot of good stuff around the Monasterary on this ##subject, like why it is often not a good idea to use things like ## print <SOCK> and $line = <SOCK> #

Hopefully the above helps. There is lots more if you look around the joint.

mitd-Made in the Dark
'My favourite colour appears to be grey.'


In reply to Re: REQ concise steps sockets using Socket.pm by mitd
in thread REQ concise steps sockets using Socket.pm by snafu

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.