http://www.perlmonks.org?node_id=319373


in reply to Socket Programming

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.