[Home]Function Calls

HomePage | RecentChanges | Preferences | My Website home page

Function Calls

#
#  Diagram of Client, Server, Database model
#
#  Doug Rice, copyright 2008
#

     Client	|	Server		|  database
-------------------------------------------------------	
		|			|
get:------------|---------+		|
		|	serve		|
display<--------|---------+		|
		|			|
 


     Client	|	Server		|  database
-------------------------------------------------------
		|			|
get:------------|---------+		|
		|	serve		|
display<--------|---------+		|
Run Scripts	|			|
display		|			|
		|			|


     Client	|	Server		|  database
-------------------------------------------------------
		|			|
get:------------|---------+		|
		|	run scripts	|
		|	serve		|
display<--------|---------+		|
Run Scripts	|			|
display		|			|
		|			|


     Client	|	Server		|  database
-------------------------------------------------------
		|			|
get:------------|---------+		|
		|	run scripts	|
		|	  +-------------|-------+			
		|			|      SQL select
		|			|     Report data
		|	  +-------------|-------+
		|	  |		|
		|	run scripts	|	
		|	serve		|
display<--------|---------+		|
Run Scripts	|			|
display		|			|
		|			|

Client Server

Socket - software to interface hardware to user. The socket accepts interupts from Network chip.

It provides call back functions to allow incoming packets to be passed to the program, and also buffers outgoing text.

Here's a sample TCP client using Internet-domain sockets:

    #!/usr/bin/perl -w
    use strict;
    use Socket;
    my ($remote,$port, $iaddr, $paddr, $proto, $line);

    $remote  = shift || 'localhost';
    $port    = shift || 2345;  # random port
    if ($port =~ /\D/) { $port = getservbyname($port, 'tcp') }
    die "No port" unless $port;
    $iaddr   = inet_aton($remote)               || die "no host: $remote";
    $paddr   = sockaddr_in($port, $iaddr);

    $proto   = getprotobyname('tcp');
    socket(SOCK, PF_INET, SOCK_STREAM, $proto)  || die "socket: $!";
    connect(SOCK, $paddr)    || die "connect: $!";
    while (defined($line = <SOCK>)) {
        print $line;
    }

    close (SOCK)            || die "close: $!";
    exit;

And here's a corresponding server to go along with it. We'll leave the address as INADDR_ANY so that the kernel can choose the appropriate interface on multihomed hosts. If you want sit on a particular interface (like the external side of a gateway or firewall machine), you should fill this in with your real address instead.

    #!/usr/bin/perl -Tw
    use strict;
    BEGIN { $ENV{PATH} = '/usr/ucb:/bin' }
    use Socket;
    use Carp;
    my $EOL = "\015\012";

    sub logmsg { print "$0 $$: @_ at ", scalar localtime, "\n" }

    my $port = shift || 2345;
    my $proto = getprotobyname('tcp');

    ($port) = $port =~ /^(\d+)$/                        or die "invalid port";

    socket(Server, PF_INET, SOCK_STREAM, $proto)        || die "socket: $!";
    setsockopt(Server, SOL_SOCKET, SO_REUSEADDR,
                                        pack("l", 1))   || die "setsockopt: $!";
    bind(Server, sockaddr_in($port, INADDR_ANY))        || die "bind: $!";
    listen(Server,SOMAXCONN)                            || die "listen: $!";

    logmsg "server started on port $port";

    my $paddr;

    $SIG{CHLD} = \&REAPER;

    for ( ; $paddr = accept(Client,Server); close Client) {
        my($port,$iaddr) = sockaddr_in($paddr);
        my $name = gethostbyaddr($iaddr,AF_INET);

        logmsg "connection from $name [",
                inet_ntoa($iaddr), "]
                at port $port";

        print Client "Hello there, $name, it's now ",
                        scalar localtime, $EOL;
            }

And here's a multithreaded version. It's multithreaded in that like most typical servers, it spawns (forks) a slave server to handle the client request so that the master server can quickly go back to service a new client.

So a Server sits listening for connections and accepts a connection. what next?

The client either reads or writes.

Lets say both ends read. There will be dead lock. The read needs to run a timer.

we can have the following combinations. two ends are called A and B.

 0 - A reads , B reads.   *** useless and dead lock.

 1 - A writes, B reads.

 2 - A reads,  B writes.

 3 - A writes, B writes.  *** useless tex buffered.

 4 - A and B both writes wait then reads. repeat until mutual end. How do you acknowledge, as both need to wriet before read.

I am not sure if it is possible to poll for data.

The LUA serial code does timed reads. It is often important to read after a delay so that the other en gets time to actually send characters.

The Perl commands do not seem to allow this.

So what this means is that the socket model is that the server sits awaiting a connections, a sequence of messages are exchanged, in an agreed sequence, either A sends and the socket closes.

This is not the asychronous listen to the left and right and above and below.

Therefore I conclude that the client server model is not that used for ISUP.

  while(){
    poll for messages,
    process
  }

HomePage | RecentChanges | Preferences | My Website home page
This page is read-only | View other revisions
Last edited November 9, 2021 8:54 pm by dougrice.plus.com
Search: