1) What is a packet? When my program reads from the socket, does it read only one packet?

A "packet" is kind of one of those made-up terms that means whatever the user wants it to mean. In the realm of TCP/IP a "packet" is a sequence of bytes that contains a sequence number, source address, destination address, and some data. As far as socket programming goes, these things are well below the level of detail you usually have to worry about. However, a particular protocol (for instance)may use the term "packet" though and would probably be referring to an individual chunk of meaningful data that is sent over a socket.

2) If the perl application on the other end sends the words "hello" and "there" separately by using 2 separate print statements, will my progam receive both words at once ("hello there") when it reads the socket?

Actually it would receive "helloworld" or perhaps "h", "e", "l", "l", etc. (depending on how you're reading) if you sent "hello" then "world" in separate print statements, but yes that's how it works. Think of sockets like you would pipes; whatever you put in them on one end can be read on the other end in the same order that it was put in.

I'm sure there are better descriptions out there, but I don't have any references handy, sorry. Google for "unix network programming" though and you'll find the definitive reference.


In reply to Re: Socket Programming by duff
in thread Socket Programming by Gorby

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.