The Simple Sockets Library makes sockets easy to use! And, it comes as public domain source code, free via the web:
As a word of warning: Nasa Federal Credit Union has been taking out $5/month from my daughter's savings account. Since this account was a "kid's" account, it tends to be inactive. I admit that I don't look at the kids' statements every month; I generally do so once per year at tax time. They claim that they called my daughter, but as its a family phone with an answering machine, I can confidently say that there was no such phone call. So, I advise you not to set up "kid" savings accounts with NASA-FCU.
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","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 Unix Sockets FAQ for Network Programming (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.
#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 */
|7 (Aug 19, 2009)||Satchel- improved Sinit.c for Windows|
|cec- Sopen(srvrname,"b") client opening blocks until server exists|
|6 (Mar 24, 2005)||Tingas - for Gnu CC, socklen_t now used instead of int|
|5 (May 24, 2004)||cec- Now supports cygwin|
|4 (Apr 22, 2004)||Wood - sprt prototyped properly|
|Wood - <strings.h> changed to <string.h>|
|3 (Apr 02, 2004)||cec- some cosmetic changes, more pointers initialized to Null, etc|
|Bourne - Mac OS-X port|
|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||BSD Sockets Primer|
|Domains and Protocols||Sockets Types and Protocols|
|Sockets Tutorial||Sockets Tutorial|
|Gnu C IPC Facilities||Sockets|
|More Sockets Links||Spencer's Socket Site|
|Sockets FAQ||Unix Sockets FAQ for Network Programming|
|Sockets Programming Fundamentals||Sockets Programming Fundamentals|
|Dealing with Floats, Structs, etc.||RPC|
The pre-compiled version of the Simple Sockets Library was compiled with the Borland C/C++ compiler.
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!
|Last Modified Aug 22, 2016 09:42:57 PM|| © 2012, Charles E Campbell