LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Blogs > rainbowsally
User Name
Password

Notices


Rate this Entry

Sockets - The lqNetDog mini-lib for socket connections

Posted 01-22-2013 at 06:40 AM by rainbowsally
Updated 01-22-2013 at 10:52 AM by rainbowsally (moved some includes)

[Bad logic level in netdog_request() presumably fixed. -rs]

Sockets - The NetDog mini-lib for socket connections

Today's feature is:
  • NetDog. :-)
  • A simple non-blocking ans (listen) and orig (connect) example.
  • Minor bundling of socket functions to greatly simplify a successful connection.

Complicating this stuff is easy. Simplifying it is the hard part.

The non-blocking setup here simplifies coding for a gui which needs to constantly be receiving events, which is what we'll be using it for, but for those with other purposes in mind, this MIGHT be the key to hacking socket security (i.e., the DOCUMENTATION) and getting your own projects rolling. ;-)

The option to the non-blocking setup for a gui application is to create threads and a mutex, which can obscure the simplicity of the basic concepts. So here's netdog version 1.0.

The functions are divided up into 'ans' as in "answer" and 'orig' as in "originate" blocks. The functions are not enforced and there's no error checking so check the header file to make sure you're using the right functions for your listener (ans) or your connector (orig).

To run the demo app (which has a very long loop timeout so that you can set DEBUG to watch the run-states change, if you want to) first do something like
Code:
xterm & # with the ampersand
and then in xterm
Code:
ans
because the answer side has to be "listening" for the originator of the connection request to connect, right?

Lots of confusing words, but if you think about it, you can't talk to someone on a phone if nobody's there to ans-wer it (the listener), and it's you that "originates" the call (connects) because they don't know who's calling or when a call might come in.

So run 'ans' first.

Then with the commandline above, your first terminal should be able to run the second app.
Code:
orig
And type in some stuff. 'bye' ends the connection side. 'shutdown' ends BOTH sides, after which (on my system) there is a 60 second timeout before 'ans' can run again, with the error indicating that the address and port are already in use.

[define DEBUG = 1 in the sources if you want to watch the 'run' loop states change if you're interested in the nuts and bolts of running a gui in the same thread as the sockets.]

Here's ans.

file: ans.cpp
purpose: source file
Code:
/* server_v4.cpp
 * by Rainbow Sally Copyright (c) 2013 Rainbow Sally, GPL 3+
 */

// Demonstrate IPv4 read / write functions for sockets programming

#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <stdarg.h>

#include <ctype.h>      // isdigit()
#include <stdlib.h>     // abort(), exit(), atoi()
#include <string.h>     // strcmp(), memset()
#include <arpa/inet.h>  // inet_addr, etc.
#include <unistd.h>     // close()
#include <signal.h>     // EADDRINUSE

#ifndef streq
#define streq(a, b) (strcmp(a, b) == 0)
#endif

void dbg(){}

#include "netdog-v1.0/netdog.h"
#include "netdog-v1.0/netdog.cpp"


void panic(const char* msg, ...)
{ 
  va_list ap;

  va_start(ap, msg);
  vprintf(msg, ap);
  va_end(ap);
  abort();
}


static bool show_listener;
static netdog_t* my_netdog;

void run();

int main(int count, char *strings[])
{ 
  dbg();
  
  bool ok;
  int portnum;
  
  const char* port_str = "9999";      // simulates user input
  const char* addr_str = "127.0.0.1"; // localhost
  
  if(!sscanf(port_str, "%d", &portnum))
    panic("Can't conver portnum\n");
  
  printf(
         "Using address '%s', port %s\n"
      "Waits for connection then echos string typed in client to\n"
      "stdout and sends the same string back.\n"
      "Press Ctrl-C to exit\n", addr_str, port_str
        );
  
  netdog_t* pobj;
  pobj = netdog_new(addr_str, portnum, 100);
  my_netdog = pobj; // for runner
  
  ok = netdog_createListener(pobj);
  if(!ok)
  {
    printf("Couldn't createListener().\n");
    if(errno == EADDRINUSE /*98*/)
    {
      printf("*** May be in 60 second OS timeout, try again later\n");
    }
    usleep(250000);
    exit(1);
  }
  
  show_listener = true; // init
  
  run();
}

typedef enum
{
  RUN_INIT,
  RUN_SHOW_LISTEN,
  RUN_ACCEPT,
  RUN_SHOW_CONN,
  RUN_RECEIVE,
  RUN_SEND,
  RUN_CLOSE,
  RUN_SHUTDOWN,
  RUN_NU
}run_states;

#if DEBUG /* set this = 1 to watch states change */
const char* state_names[] = 
{
  "RUN_INIT",
  "RUN_SHOW_LISTEN",
  "RUN_ACCEPT",
  "RUN_SHOW_CONN",
  "RUN_RECEIVE",
  "RUN_SEND",
  "RUN_CLOSE",
  "RUN_SHUTDOWN",
  0
};
#endif


void run()
{
  netdog_t* pobj = my_netdog;
  
  bool ok;
  // outer loop is continuous
  
  int loop_state = 0;
  
  bool shuttingdown = false;
  bool closing = false;
  
  for(;;)
  { 
    usleep(250000); // simulate ui timeout (actually 20 ms)

#if DEBUG
    printf("-- %s --\n", state_names[loop_state]);
#endif
    
    switch(loop_state)
    {
      case RUN_INIT: // init
        shuttingdown = false;
        closing = false;
            
        loop_state = RUN_SHOW_LISTEN;
        break;
        
      case RUN_SHOW_LISTEN:
        printf("Listening..\n");
        loop_state = RUN_ACCEPT;
        break;
      
      case RUN_ACCEPT: // accept
        // when using SOCK_NONBLOCK we need to verify that the connection was there
        // and skip back to the loop for a timeout.
        ok = netdog_accept(pobj);      
        if(ok)
          loop_state = RUN_SHOW_CONN;
        
        // else try again
        break; 
      
      case RUN_SHOW_CONN: // display connection
        
        // Here's ntop() Network to Presentation format for displaying the address
        fprintf(stderr, "Connected: %s port=%d, client id = %d\n",
              inet_ntop(AF_INET, &pobj->addr.sin_addr, pobj->indata, pobj->datamax),
                        ntohs(pobj->addr.sin_port),
                              pobj->rx_fd
             );
        loop_state = RUN_RECEIVE;
        break;
        
      case RUN_RECEIVE: // receive
        
        // receive and echo back
        netdog_receive(pobj);

        // need better way to tell if the connection 
        // is broken in terminal.  gui = ok, just 
        // set closing = true and loop_state = 6.
        if(pobj->nbytes <= 0)
          break; // repeat
  
        if(streq(pobj->indata, "shutdown\n"))
          shuttingdown = true;
        else if(streq(pobj->indata, "bye\n"))
          closing = true;
        
        // in either case...
        loop_state = RUN_SEND;
        break;
        
      case RUN_SEND: // send

        netdog_send(pobj, pobj->indata, pobj->datamax);
        printf("server echoing: %s\n", pobj->outdata);
  
        if(closing)
          loop_state = RUN_CLOSE;
        else if(shuttingdown)
          loop_state = RUN_SHUTDOWN;
        else
          loop_state = RUN_RECEIVE; // again
        
        break;
        
      case RUN_CLOSE: // close | shutdown
        
        fprintf(stderr, "Closing client %d\n", pobj->rx_fd);
        netdog_close(pobj);
        if(shuttingdown)
          loop_state = RUN_SHUTDOWN;
        else
          // show_listener = true;
          loop_state = RUN_SHOW_LISTEN; // show listener
        break;
        
      case RUN_SHUTDOWN: // close server
        // TODO: how do we un-bind so we don't have to do this lengthy timeout?
        netdog_delete(&pobj);
        fprintf(stderr, "Notice:\n  It takes the OS a full 60 seconds to timeout after shutdown\n  so this address and port can't be used again for about a minute.\n");
      
        // timeout and uninit
        return;
    }// switch loop_state
  } // for(;;)
}
And here's orig


file: orig.cpp
purpose: source file
Code:
/* client_v4.cpp
 * by Rainbow Sally Copyright (c) 2013 Rainbow Sally, GPL 3+
 */

// Demonstrate IPv4 read / write functions for sockets programming

#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <stdarg.h>

#include <ctype.h>      // isdigit()
#include <stdlib.h>     // abort(), exit(), atoi()
#include <string.h>     // strcmp(), memset()
#include <unistd.h>     // close()

#ifndef streq
#define streq(a, b) (strcmp(a, b) == 0)
#endif

void dbg(){}

#include "netdog-v1.0/netdog.h"
#include "netdog-v1.0/netdog.cpp"

void panic(const char* msg, ...)
{   
  va_list ap;
  va_start(ap, msg);
  vprintf(msg, ap);
  va_end(ap);
  abort();
}


typedef enum
{
  RUN_INIT,
  RUN_GET_INPUT,
  RUN_SEND,
  RUN_RECEIVE,
  RUN_CLOSE_CONN,
  RUN_SHUTDOWN,
  RUN_DELETE,
  RUN_EXIT,
  RUN_NU
}run_states;

#if DEBUG /* set DEBUG to 1 to watch states change */
const char* state_names[] =
{
  "RUN_INIT",
  "RUN_GET_INPUT",
  "RUN_SEND",
  "RUN_RECEIVE",
  "RUN_CLOSE_CONN",
  "RUN_SHUTDOWN",
  "RUN_DELETE",
  "RUN_EXIT",
  0
};
#endif

// MSG_OOB 
// MSG_PEEK 
// MSG_DONTROUTE
#define MSG_FLAGS 0 /* default */
extern "C" {
  // noop
}

    
int main(int argc, char **argv)
{ 
  dbg();
  bool ok;
  const char* addr_str = "127.0.0.1";
  const char* port_str = "9999";
  int portnum;
  
  printf(
         "Using address '%s', port %s\n"
         "Type text to send to server, 'bye' to end\n"
         , addr_str, port_str
        );
  
  if(!sscanf(port_str, "%d", &portnum))
    panic("Can't convert portnum\n");

  netdog_t* pobj;
  pobj = netdog_new(addr_str, portnum, 100);
  
  // struct sockaddr_in addr;
  
  // no listener for originator, just 'request' a connection.
  ok = netdog_request(pobj);
  
  // bool shuttingdown = false;
  int loop_state = 0;
  bool shuttingdown = false;
  bool closing = false;
  
  for(;;)
  {
    
    usleep(250000); // simulate ui timeout (actually 20 ms)
    // if window not visible, loop_state = 7;
    
#if DEBUG
    printf("-- %s --\n", state_names[loop_state]);
#endif
        
    switch(loop_state)
    {
      
      case  RUN_INIT: // init
        shuttingdown = false;
        closing = false;
        loop_state = RUN_GET_INPUT;
        break;
      
      case RUN_GET_INPUT: // get user input        
        fgets(pobj->indata, pobj->datamax, stdin);
        loop_state = RUN_SEND;
        break;
        
      case RUN_SEND: // send/shutdown
         
        netdog_send(pobj, pobj->indata, pobj->datamax);
        
        if(streq(pobj->indata, "shutdown\n"))
          shuttingdown = true;
        
        loop_state = RUN_RECEIVE;
        break;
        
      case RUN_RECEIVE: // receive
        
        netdog_receive(pobj);
        
        printf("client recieved echo: %s", pobj->indata);
        if(streq(pobj->indata, "bye\n"))
          loop_state = RUN_CLOSE_CONN;
        else if (shuttingdown)
          loop_state = RUN_SHUTDOWN;
        else
          loop_state = RUN_GET_INPUT; // get input
        break;
        
      case RUN_CLOSE_CONN: // close connection        
        
        netdog_close(pobj);
        loop_state = RUN_DELETE;
        break;
                
      case RUN_SHUTDOWN: // shut down
        loop_state = RUN_DELETE;
        break;
        
      case RUN_DELETE:
        netdog_delete(&pobj);
        loop_state = RUN_EXIT;
        
      case RUN_EXIT:
        
        // uninit, close window or whatever
        return 0;
        ;
    } // switch loop_state
  } // for(;;)
  return 0;
}
And here's a self extractor for the netdog includes. Coulda been a lib, but then you couldn't mess with the code as easily if you want to experiment with it.

[Had a bad logic level in netdog_request() now presumably fixed. -rs]

file: netdog-v1.0.sfxz
purpose: utility (executable)
Code:
#!/bin/sh
# base64 self extractor
# file: netdog-v1.0

filename=netdog-v1.0

# don't allow user to click on the file
if ! tty >/dev/null; then
  xmessage -center "
  $(basename $0)
  must be run in a terminal 
  "
  exit
fi

# create and/or clear out tmp dir
mkdir -p $HOME/tmp/sfxz
rm -rf $HOME/tmp/sfxz/*
base64 -d << _BEOF >$HOME/tmp/sfxz/$filename.xz
/Td6WFoAAATm1rRGAgAhARYAAAB0L+Wj4E//DIRdABcLykbiRKirO1dDptP+qr5QYMj79B/531K0
n7j/oqEGliXQa6P5Exem3kFQUxTWEKExxM462VsDT2wWAH4sdmFnyKgOmX06mWyqpslldL3zB8qR
DVEIz16UPR8+vEHjtCgzY7Ra0LKcA3+gJabEhOhCypJtlDYfW3ZGyOqUPYX6Hv6UQ8LYojiO8mK0
s1RT5hvXT+Q3CCUKFOBSzvrxGzlIytmMVs1adtJAFkhzJ+qzYdnM8PiYYyAFWhsqbrvxMLBV5DRl
quTZfdGuo9AZANaBvCaAojdIxojdwtzlv7OdQXdXoBwldGWo+GG43jr8FQO7eskvNfP1WjCX1Llw
zE+FWm+BGcaMsvWELmCD5ueh3SibGaqgBNta/6eKRhLZ0mKIJuPlEmL5yEn4X8J6W1ME8TYvTvh1
N2EOt+shJSeLQXiDFF++SN46fVhEdghw0ftOWDBLgJk2qhXYQ1RSxF/c4ZM1jC8b6c7IPQXt2p4u
yttyuA1+jDSyRK8dFTth28lQDmgOO/9myDiei6VGipo3MnOM5O9Q96xcVcd+uHwDdUobkZWcAT2r
Byj5n55MdMJ0DyUVYJWPMXtN10gj5P6wITbVWDuF1+yb7qEYQdcUkl+oS6pbeOxUOfbuLOR4FUb+
SYYrzt7DhKUjTjYVLtT1ZMpTQvmYctHUz0VUAfu8KlaIYv3CW4oJEV2tN7S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sLYLcpeNXRs
EvI8ZAmBuHy1+nS/8MFEGXbPcStb2qONzsTHFdjy8tUZRCdphPJ+2k5pKW4DmaKTkZzyzygjB/Ky
CQ39myqn3ZWRHbgcbRezVYfarKwDQwy0mxy+ickf40p+gh8bFFleYue0eDF7pY2mtpmjq5lHVObj
Cba/wDVjREldxgshy1lBthHmLIN4SZhCtSQ1JkoZQJ6jlwV9xbLBZqjoYMMz0cqOuzlGfOWy8pCl
yaigt6FaqT1yxg75wI/vzD40eOEfCYSFEjlVCl/aOWhq77LgRYpGVFAwz2CnUyeTgSvBUwMYxha5
oMUgu6XuZYstB1JLY5uJI8lFsJsK2Ivb4R3mI3l1+c1pgjJWhlzUEezWAAA2IClTqvRkPwABoBmA
oAEA2uqDmrHEZ/sCAAAAAARZWg==
_BEOF

(cd $HOME/tmp/sfxz && tar -xaf netdog-v1.0.xz)
rm -f $HOME/tmp/sfxz/netdog-v1.0.xz
 
cat << _BEOF > $HOME/tmp/sfxz/post-extract
#!/bin/sh

is_yes() # returns OK if first char is Y or y
{
  local key=`echo $1 | cut -b1 | sed 's/y/Y/; /Y/!d'`
  [ "$key" == 'Y' ] && return 0 # true
  return 1 # false
}

if [ -e netdog-v1.0 ]; then
  printf "
  Overwrite existing file(s)? [N/y]:"
  read key
  if ! is_yes $key ;then
  echo "Aborting.."
    exit 0
  fi
fi

mv $HOME/tmp/sfxz/netdog-v1.0 .
_BEOF

sh $HOME/tmp/sfxz/post-extract
rm -rf $HOME/tmp/sfxz/*
rmdir $HOME/tmp/sfxz 2>/dev/null || true
rmdir $HOME/tmp 2>/dev/null || true


Here's the mc2 definitions, from which you can probably figure out how to generate your own makefile if you're good at that kind of stuff. Or just run 'mc2 -init' if you have the libLQ d/load here http://www.linuxquestions.org/questi...support-34783/

file: mc2.def
purpose: source file
Code:
# mc2.def template created with Makefile Creator 'mc2'

## sandbox path and other new variables
PREFIX = $(HOME)/usr32
BUILDDIR := $(PWD)

# output name override
OUTNAME = MULTI

SRCDIR = .
OBJDIR = o
BINDIR = .

# compile function overrides
COMPILE = g++ -m32 -c -o # COMPILE <output_file> ...
# CFLAGS = -Wall -g3 # debug
CFLAGS = -Wall -O2 # optimized
INCLUDE = -I $(SRCDIR) -I$(PREFIX)/include -I /usr/include 

# link function overrides
LINK = g++ -m32 -o # LINK <output_file> ...
LDFLAGS = 
LIB = -L/usr/lib -L$(PREFIX)/lib

semiclean:
  @rm -f $(OBJ)
  @rm -f *~ */*~ */*/*~ */*/*/*~

strip:
  @strip $(MAIN)
  @make semiclean

clean:
  @rm -f $(MAIN)
  @rm -f $(OBJ)
  @rm -f *.kdevelop.pcs *.kdevses
  @rm -f *~ */*~ */*/*~ */*/*/*~
 
force: # used to force execution
- The Computer Mad Science Team

:-)
Posted in Uncategorized
Views 1361 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 10:45 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration