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:

The Simple Sockets Library is available by clicking on ssl-7c.tar.bz2. 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-code 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 example).

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).


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
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&rt; changed to <string.h&rt;
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-7c.tar.bz2
Updated Aug 22, 2005
PGP Signature for the Simple Sockets Library Source ssl-7.md5
Updated Aug 22, 2005
BSD Sockets Primer Sockets Primer
Domains and Protocols Domains and Protocols
Gnu C IPC Facilities Sockets
More Sockets Links Spencer's Socket Site
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.


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.

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 the email address and it'll work. Hate e-spam!


Home You are visitor

Last Modified Mar 31, 2006 10:13:50 AM © 2006, Charles E Campbell, Jr.