GreenDragonHead

The Simple Sockets Library

Authors: Charles E. Campbell, Jr.
Terry McRoberts

The Simple Sockets Library makes sockets easy to use! And, it comes as public domain source code, free via the web:

You may get a copy of the Simple Sockets Library by clicking on ssl_7.tar.gz. Its also been registered at Freshmeat.net.

The Simple Sockets Library's main purpose is to provide an Application Programming Interface that strongly resembles the standard C library's file handling interface. Thus programmers find that the Simple Sockets Library's learning curve is particularly short. As a secondary purpose the Simple Sockets Library helps programmers avoid some common programming problems with sockets (avoided: large buffers that don't transfer in their entirety without special effort, the Nagle algorithm's practical effect of often limiting one to five transfers per second, servers whose ports refuse to re-open until two minutes have passed, etc). Strings are null-byte terminated just like regular C/C++ strings, facilitating their ease of use in C/C++ programming.

The Simple Sockets Library preferentially uses names for its servers rather than requiring hard-coded port numbers. Imagine if, instead of files having names, everyone went about saying "use sector 4 and track 14" or somesuch thing. This situation reflects what we now have with sockets -- and when two programs use the same port number for their servers, they can't co-exist simultaneously on a system. However, especially for those whose programs must interface with other programs using hard-coded port numbers, the Simple Socket Library also supports hard-coded port numbers.

The Simple Sockets Library opens streaming sockets. Thus the Simple Sockets Library's sockets provide guaranteed delivery of information in the correct order (unlike datagrams, for instance).

The PortMaster (Spm), source code for which is part of the library, provides a "phonebook" to map server names to dynamically allocated port numbers. Port numbers thus won't clash; the operating system determines which ones are currently available and the PortMasters effectively publish the result. The programmer only need write

Sopen("srvrname","s")
or
Sopen("srvrname","c")
as needed because the Simple Sockets Library transparently handles all transactions with the PortMasters.

The PortMasters provide security, too, in the form of lists of IP addresses that they will permit contact from.

If you'd like to find out more about sockets and tcp/ip, check out Vic Metcalfe's Sockets FAQ (see the SSL mentioned in the FAQ's answer to Category 2, Q12).

Note: when building the Simple Sockets Library, if you receive link messages complaining that things like bind(), send(), recv(), etc are "undefined references", that means that the link line isn't including your basic sockets library/libraries. For example, for Solaris, you will find that there's a "for Solaris 2.1" comment in the Makefile that instructs you to uncomment out a LOADLIBES definition that includes "-lnsl" on the link line. You may have to do some sleuthing on your system using the man pages to find out what your sockets libraries are called and include them in the LOADLIBES list.


Examples

A) A Server/Accept
        #include "sockets.h"
        Socket *srvr;
        Socket *skt;
        srvr= Sopen("srvrname","s");     /* open a server called "srvrname"      */
        skt = Saccept(srvr);             /* accept a client on the given server  */
        Sputs("hello client",skt);       /* send a string to the client          */
        Sclose(skt);                     /* close the accept Socket              */
        Sclose(srvr);                    /* close the server                     */

B) A Client

        #include "sockets.h"
        char    buf[BUFSIZE];
        Socket *client;
        client= Sopen("srvrname","c");   /* open client to the "srvrname" server */
        Sgets(buf,BUFSIZE,client);       /* get a string from the server         */
        printf("server said <%s>\n",buf);/* print out what the client got        */
        Sclose(client);                  /* close the client Socket              */


Version Updates
7 (Aug 19, 2009) Satchel- improved Sinit.c for Windows
Included "b" option for Sopen (block until server exists)
6 (Mar 24, 2005) Tingas - for Gnu CC, socklen_t now used instead of int
Sopen(srvrname,"b") - a blocking wait for client opening
5 (May 24, 2004) Now supports cygwin
4 (Apr 22, 2004) Wood - sprt prototyped properly
Wood - <strings.h> changed to <string.h>
3 (Apr 02, 2004) some cosmetic changes, more pointers initialized to Null, etc
Bourne - Mac OS-X port


Links

Description Link
Simple Sockets Library Source ssl_7.tar.gz Updated Aug 19, 2009
MD5 Sum for the Simple Sockets Library Source ssl_7.md5 Updated Aug 19, 2009
Simple Sockets Library Manual ssl_7 sockets manual (postscript) New Sep 29, 2009
BSD Sockets Primer Sockets Primer
Domains and Protocols Domains and Protocols
Gnu C IPC Facilities Sockets
More Sockets Links Spencer's Socket Site
Programming with Sockets Sockets Programming
Sockets FAQ Vic Metcalfe's Sockets FAQ
Sockets Programming Fundamentals Sockets Programming
Dealing with Floats, Structs, etc. RPC

The pre-compiled version of the Simple Sockets Library was compiled with the Borland C/C++ compiler.


Port Requests

Have you ported the Simple Sockets Library to a new operating system? Please send a copy to NdrOchip@ScampbellPfamily.AbizM so I can make it available to all. Take out the NOSPAM embedded in the email address and it'll work. Hate e-spam!


John 3:16
For God so loved the world that he gave His one and only Son, that whoever believes in Him shall not perish but have eternal life.


Home

Last Modified Aug 23, 2011 12:59:26 PM © 2011, Charles E Campbell, Jr.