>"Getting my feet wet with Sockets, BSD style."

>Just came across this site with an interesting tutorial:
BSD Sockets: A Quick And Dirty Primer
by Jim Frost
February 13, 1990
URL: http://www.softlab.ece.ntua.gr/facilities/documentation/unix/sockets.html

BSD Sockets are thought to be hard to understand at first. I guess I’ll see for my self as I read through this tutorial.

The BSD socket is one of the primary medium of communication between different processes much like the telephone.

There are many types of socket schemes which are not to be confused with socket types, but for this tutorial only one socket scheme will be discussed in detail and this is the AF_INET socket scheme. Sockets are created with the socket() command which basically instantiates a connection with the addressing scheme specified as a parameter. The two most used addressing schemes are AF_UNIX and AF_INET. The AF_UNIX socket scheme uses UNIX pathnames to identify sockets and is useful for IPC between processes on the same machine. The AF_INET scheme uses Internet addresses in addition to a machine address and a port number which can allow form more than one socket connection on each macnine.

Now on to socket types. In addition to specifing the socket schemes and port the socket type must also be specified to the socket() command. The two most commonly used socket types are SOCK_STREAM and SOCK_DGRAM. SOCK_STREAM looks like what I will need, to read in those characters from vortex.labs.pulltheplug.com in order to get started with the wargame. SOCK_STREAM allows for data to move across the network as a stream of characters. SOCK_DGRAM allows for chunks of characters to come through as one at a time and are call datagrams.

When a socket is created that socket must then be binded to an address to listen to. This is done with the bind() function when working with sockets. Also with SOCK_STREAM there is the ability to work with incoming connections in a queue like fashion. To handle connections in a queue like fashion does not mean there is an unlimited number of space to have connections queued up in. We are limited to a maximum of five connections. The listen() function is use to set the number of request to have in a queue. Once we reach this maximum connections will be denied.

Now that I have a semi-ok grep on how socket(), bind() and listen() are used lets put it to practice.

/* This is not my code
* Taken from the URL above
*/

Advertisements
This entry was posted in Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s