By definition of a server yes they are all servers.
Client/Server model is where a client (such as a web browser though this is only one type of client) connects to a server which provides services to the client which the client then does something with (in this case renders the HTML provided by the web server into a web page.) Another way to say it is that server is a specialized type of daemon or background process that loops over and over and listens for connections on a socket or sockets to answer requests. Apache does open multiple instances to listen for web requests from clients eg it is multi-threaded.
I wrote a C based cgi which connected by socket to a chat perl server which then passed the html output back to the cgi and then to apache.
You could also for example write a simple daemon in perl to listen for requests and return the remote external ip address for use in dynamic dns. Then write a client which connects to the server, gets the ip, then updates a DNS record by API call to somewhere.
Something like this...
The Server
#/usr/local/bin/perl
$ver = "0.10";
use Socket;
$dir = "$ENV{'HOME'}/bin/localdns";
if (fork) { exit(0); }
&init;
&socket;
sub webprint {
send(SOCKET,"@_",0);
}
while (1) {
my ($raddr,$remote_addr);
# $time = time();
if (($raddr = accept(SOCKET, SSOCKET))) {
($client_port,$client_addr) = unpack_sockaddr_in($raddr);
$remote_addr = inet_ntoa ($client_addr);
if (0) { # not reading the socket
setsockopt(SOCKET, SOL_SOCKET, SO_LINGER, pack("ii", 0, 0));
$rlen = sysread(SOCKET, $inp, 1024);
if ($rlen < 1024) {
if ($rlen < 1) {
close(SOCKET);
next;
} else {
$inp =~ s/\0+//;
while ($inp !~ /\n/ && $rlen > 0) {
$rlen = sysread(SOCKET, $temp, 1024);
if ($rlen < 1024) { $temp =~ s/\0+//; }
$inp .= $temp;
}
}
} else {
while ($inp !~ /\n/ && $rlen > 0) {
$rlen = sysread(SOCKET, $temp, 1024);
if ($rlen < 1024) { $temp =~ s/\0+//; }
$inp .= $temp;
}
}
} # we are not reading the socket
} else {
next;
}
#print STDRR "$remote_addr\n";
#print STDOUT "$remote_addr\n";
webprint "$remote_addr";
# webprint "</b></nobr>";
close(SOCKET);
}
close(SOCKET);
close(SSOCKET);
###################
# server routines #
###################
# things done once as the server start up
sub init {
chop($host = `hostname`);
# prevent sigpipe crashes
$SIG{PIPE} = 'IGNORE';
# allow signal alarm to break some routines that lock
$SIG{'ALRM'} = \&sig_alarm;
# allow sighup to do routine things
$SIG{HUP} = \&sig_hup;
# server conditional code
$mainhost = "myhost.com";
$mysql_host = "localhost";
$svip = "127.0.0.1";
$port = "43636";
open(STDERR, ">>$dir/error_ipserv") || die "Can't open $dir/error_ipserv";
$oldfh = select STDERR; $|=1; select($oldfh);
}
sub socket {
getservbyport($port, "tcp");
$proto = getprotobyname("tcp");
socket(SSOCKET, PF_INET, SOCK_STREAM, $proto) || die "Socket $!\n";
setsockopt(SSOCKET, SOL_SOCKET, SO_REUSEADDR, pack("l", 1)) || die "setsockopt: $!\n";
# this should work for any local or external address
bind(SSOCKET, sockaddr_in($port, INADDR_ANY)) || die "Bind $!\n";
# for specific ip
# bind(SSOCKET, sockaddr_in($port, inet_aton("$svip"))) || die "Bind $!\n";
listen(SSOCKET,512) || die "Listen $!\n";
vec ($rin, $sockweb_fd = fileno(SSOCKET), 1) = 1;
print STDERR "Socket is set up and listening.\n";
}
# good for timeout of connects that do not connect fast enough
sub sig_alarm {
return;
}
# good to tell the server to do things at routine
# intervals or to save scores or shutdown even
sub sig_hup {
return;
}
The Client
#!/usr/local/bin/perl
use Socket;
$remote_hostname = "myhost.com";
$port = "43636";
socket(SHANDLE, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $!;
my $dest = sockaddr_in ($port, inet_aton($remote_hostname));
connect (SHANDLE, $dest) || die $!;
## ONE WAY TO SEND
## $data = "Hello";
## send (SOCKET, $data);
## ANOTHER WAY TO SEND
#select (SHANDLE);
#print "\n";
# THIS
# recv (SHANDLE, $buffer);
# OR
$newip = <SHANDLE>;
close(SHANDLE);
print "$newip\n";
Isn't it true that a Node.js based server (i.e. code) will still be placed within something like Nginx to run?No, that's incorrect