MySVC
an open source UNIX framework for shell script based web services provider
»Home
»Tools
»Man Page
»User Guide
»ChangeLog
»Installation
»Source Code
»Downloads
»FAQ
»Support
»License

»My Apps

Table of Contents

Introduction

MySVCD (My Service Daemon) is an expect script to be used as configurable generic (tcp/ip or http) server or client, where single operation implementation can be implemented as expect procedure or external process such as a shell script.

Using mysvcd as server

Test Server (default)

Usage
  mysvcd [-l] [-p <port>]
    (put on stdout requests from client and get from stdin responses for client)
  • -p <port> specify the tcp/ip server port (default is 1036)

  • -l option enable logs.

  • the client request is write on standard output (one or more lines)

  • the server response is read from standard input (one or more lines)

When log is enabled each request from client is echoed to stdout so it is written twice.

Example:

Server Side without log enabled
$ mysvcd
my request 1...
my response 1...
my last request...
my last response...
Server Side with log enabled
$ mysvcd -l
2014-05-12 23:48:16 0   I start [8012]
2014-05-12 23:48:17 0   I server 192.168.0.105:10306
2014-05-12 23:48:33 0   I opening connection to client 127.0.0.1:50797
2014-05-12 23:48:33 0   I waiting for request from client 127.0.0.1:50797
2014-05-12 23:48:44 0   I received request from client 127.0.0.1:50797
my request 1...
my request 1...
my response 1...
2014-05-12 23:49:06 0   I sending response to client 127.0.0.1:50797
my response 1...
2014-05-12 23:49:35 0   I received request from client 127.0.0.1:50797
my last request...
my last request...
my last response...
2014-05-12 23:49:59 0   I sending response to client 127.0.0.1:50797
my last response...
^C2014-05-12 23:50:04 0   I received signal SIGINT
2014-05-12 23:50:04 0   I stop [8012]
Client Side
$ telnet localhost 10306
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
my request 1...
my response 1...
my last request...
my last response...
Connection closed by foreign host.

Generic Server (default if /path/to/server is specified)

Usage
  mysvcd [-1] [-l|-d [-l -o <logfile> [-L <loglevels>]]] [-p <port>] /path/to/server
    (put on server stdin requests from client
     get from server stdout response for client
     where server is any executable application)

The server is an external application that:

  • read the client requests from standard input

  • process the client requests

  • write the server responses to standard output

If -1 option is not specified, a connection with server is opened first once, when the client open connection, and closed when the server exits

  • The client requests are sent to stdin of server

  • The server responses are read from stdout of server

If -1 option is specified a single instance of server is shared by all clients

Example:

Server Script (myserver.sh)
#!/bin/sh

while :
do
  read request

  echo "received request $request ..."
  echo "response to request <$request> ..."

  if [ "$request" = "quit" ]
  then
    echo "exit"

    exit
  fi
done
Server Side without log enabled
$ mysvcd /path/to/myserver.sh
Server Side with log enabled (without -1 option)
$ mysvcd -l /path/to/myserver.sh
2014-06-07 00:40:18 0   I start [2122]
2014-06-07 00:40:18 0   I server 192.168.0.104:1036
2014-06-07 00:40:24 0   I opening connection to client 127.0.0.1:49884
2014-06-07 00:40:24 0   I executing server /path/to/myserver.sh
2014-06-07 00:40:24 0   I waiting for request from client 127.0.0.1:49884
2014-06-07 00:40:28 0   I received request from client 127.0.0.1:49884
myrequest1
2014-06-07 00:40:28 1   I received response from server for client 127.0.0.1:49884
server <2125>, received request myrequest1 ...
2014-06-07 00:40:28 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:40:28 1   I received response from server for client 127.0.0.1:49884
server <2125>, response to request <myrequest1> ...
2014-06-07 00:40:28 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:40:33 0   I received request from client 127.0.0.1:49884
myrequest2
2014-06-07 00:40:33 1   I received response from server for client 127.0.0.1:49884
server <2125>, received request myrequest2 ...
2014-06-07 00:40:33 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:40:33 1   I received response from server for client 127.0.0.1:49884
server <2125>, response to request <myrequest2> ...
2014-06-07 00:40:33 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:40:50 0   I opening connection to client 127.0.0.1:49885
2014-06-07 00:40:50 0   I executing server /path/to/myserver.sh
2014-06-07 00:40:50 0   I waiting for request from client 127.0.0.1:49885
2014-06-07 00:41:01 0   I received request from client 127.0.0.1:49885
myrequest3
2014-06-07 00:41:01 1   I received response from server for client 127.0.0.1:49885
server <2130>, received request myrequest3 ...
2014-06-07 00:41:01 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:01 1   I received response from server for client 127.0.0.1:49885
server <2130>, response to request <myrequest3> ...
2014-06-07 00:41:01 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:15 0   I received request from client 127.0.0.1:49885
myrequest4
2014-06-07 00:41:15 1   I received response from server for client 127.0.0.1:49885
server <2130>, received request myrequest4 ...
2014-06-07 00:41:15 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:15 1   I received response from server for client 127.0.0.1:49885
server <2130>, response to request <myrequest4> ...
2014-06-07 00:41:15 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:25 0   I received request from client 127.0.0.1:49884
quit
2014-06-07 00:41:25 1   I received response from server for client 127.0.0.1:49884
server <2125>, received request quit ...
2014-06-07 00:41:25 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:41:25 1   I received response from server for client 127.0.0.1:49884
server <2125>, response to request <quit> ...
2014-06-07 00:41:25 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:41:25 1   I received response from server for client 127.0.0.1:49884
server <2125>, exit
2014-06-07 00:41:25 1   I sending response to client 127.0.0.1:49884
2014-06-07 00:41:25 0   I detected EOF from server for client 127.0.0.1:49884
2014-06-07 00:41:25 0   I closing server for client 127.0.0.1:49884
2014-06-07 00:41:25 0   I closing connection to client 127.0.0.1:49884
2014-06-07 00:41:34 0   I received request from client 127.0.0.1:49885
quit
2014-06-07 00:41:34 1   I received response from server for client 127.0.0.1:49885
server <2130>, received request quit ...
2014-06-07 00:41:34 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:34 1   I received response from server for client 127.0.0.1:49885
server <2130>, response to request <quit> ...
2014-06-07 00:41:34 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:34 1   I received response from server for client 127.0.0.1:49885
server <2130>, exit
2014-06-07 00:41:34 1   I sending response to client 127.0.0.1:49885
2014-06-07 00:41:34 0   I detected EOF from server for client 127.0.0.1:49885
2014-06-07 00:41:34 0   I closing server for client 127.0.0.1:49885
2014-06-07 00:41:34 0   I closing connection to client 127.0.0.1:49885
Client 1 Side (without -1 option)
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest1
server <2125>, received request myrequest1 ...
server <2125>, response to request <myrequest1> ...
myrequest2
server <2125>, received request myrequest2 ...
server <2125>, response to request <myrequest2> ...
quit
server <2125>, received request quit ...
server <2125>, response to request <quit> ...
server <2125>, exit
Connection closed by foreign host.
Client 2 Side (without -1 option)
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest3
server <2130>, received request myrequest3 ...
server <2130>, response to request <myrequest3> ...
myrequest4
server <2130>, received request myrequest4 ...
server <2130>, response to request <myrequest4> ...
quit
server <2130>, received request quit ...
server <2130>, response to request <quit> ...
server <2130>, exit
Connection closed by foreign host.
Server Side with log enabled (with -1 option)
$ mysvcd -1 -l /path/to/myserver.sh
2014-06-07 23:42:12 0   I start [9879]
2014-06-07 23:42:12 0   I server 192.168.0.104:1036
2014-06-07 23:42:35 0   I opening connection to client 127.0.0.1:57259
2014-06-07 23:42:35 0   I executing server /path/to/myserver.sh
2014-06-07 23:42:35 0   I unique instance of server shared by clients
2014-06-07 23:42:35 0   I waiting for request from client 127.0.0.1:57259
2014-06-07 23:43:08 0   I received request from client 127.0.0.1:57259
myrequest5
2014-06-07 23:43:08 1   I received response from server for client 127.0.0.1:57259
server <9883>, received request myrequest5 ...
2014-06-07 23:43:08 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:08 1   I received response from server for client 127.0.0.1:57259
server <9883>, response to request <myrequest5> ...
2014-06-07 23:43:08 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:26 0   I received request from client 127.0.0.1:57259
myrequest6
2014-06-07 23:43:26 1   I received response from server for client 127.0.0.1:57259
server <9883>, received request myrequest6 ...
2014-06-07 23:43:26 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:26 1   I received response from server for client 127.0.0.1:57259
server <9883>, response to request <myrequest6> ...
2014-06-07 23:43:26 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:34 0   I opening connection to client 127.0.0.1:57264
2014-06-07 23:43:34 0   W refused connection to client 127.0.0.1:57264
2014-06-07 23:43:45 0   I received request from client 127.0.0.1:57259
quit
2014-06-07 23:43:45 1   I received response from server for client 127.0.0.1:57259
server <9883>, received request quit ...
2014-06-07 23:43:45 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:45 1   I received response from server for client 127.0.0.1:57259
server <9883>, response to request <quit> ...
2014-06-07 23:43:45 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:45 1   I received response from server for client 127.0.0.1:57259
server <9883>, exit
2014-06-07 23:43:45 1   I sending response to client 127.0.0.1:57259
2014-06-07 23:43:45 0   I detected EOF from server for client 127.0.0.1:57259
2014-06-07 23:43:45 0   I closing server for client 127.0.0.1:57259
2014-06-07 23:43:45 0   I closing connection to client 127.0.0.1:57259
Client 1 Side (with -1 option)
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest5
server <9883>, received request myrequest5 ...
server <9883>, response to request <myrequest5> ...
myrequest6
server <9883>, received request myrequest6 ...
server <9883>, response to request <myrequest6> ...
quit
server <9883>, received request quit ...
server <9883>, response to request <quit> ...
server <9883>, exit
Connection closed by foreign host.
Client 2 Side (with -1 option)
telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
Connection closed by foreign host.

Simple Server

Usage
  mysvcd [-1] -s [-l|-d [-l -o <logfile> [-L <loglevels>]]] [-p <port>] /path/to/server
    (put on server stdin each line read from client as request
     get from server stdout response for client)

The server is an external application that:

  • read the client requests from standard input (a single line)

  • process the client requests

  • write the server responses to standard output (one or more lines)

If -1 option is not specified a connection with client is opened when the client open connection and closed after server exits

  • The client requests are sent to stdin of server

  • The server responses are read from stdout of server

If -1 option is specified the connection with client is opened when the client open connection and keeped opened even when the server exits

Server Side with log enabled (without -1 option)
$ mysvcd -l -s /path/to/myserver.sh
2014-06-09 22:37:22 0   I start [3959]
2014-06-09 22:37:22 0   I server 192.168.0.104:1036
2014-06-09 22:37:35 0   I opening connection to client 127.0.0.1:51741
2014-06-09 22:37:35 0   I waiting for request from client 127.0.0.1:51741
2014-06-09 22:37:46 0   I received request from client 127.0.0.1:51741
myrequest1
2014-06-09 22:37:46 0   I executing external application /path/to/myserver.sh
2014-06-09 22:37:46 1   I received response from external application /path/to/myserver.sh for client 127.0.0.1:51741
server <3966>
2014-06-09 22:37:46 1   I sending response to client 127.0.0.1:51741
2014-06-09 22:37:46 1   I received response from external application /path/to/myserver.sh for client 127.0.0.1:51741
server <3966>, response to request <myrequest1>
2014-06-09 22:37:46 1   I sending response to client 127.0.0.1:51741
2014-06-09 22:37:46 0   I detected EOF from external application /path/to/myserver.sh for client 127.0.0.1:51741
2014-06-09 22:37:46 0   I closing external application /path/to/myserver.sh for client 127.0.0.1:51741
2014-06-09 22:37:46 0   I closing connection to client 127.0.0.1:51741
2014-06-09 22:38:07 0   I opening connection to client 127.0.0.1:51828
2014-06-09 22:38:07 0   I waiting for request from client 127.0.0.1:51828
2014-06-09 22:38:11 0   I received request from client 127.0.0.1:51828
myrequest2
2014-06-09 22:38:11 0   I executing external application /path/to/myserver.sh
2014-06-09 22:38:11 1   I received response from external application /path/to/myserver.sh for client 127.0.0.1:51828
server <3971>
2014-06-09 22:38:11 1   I sending response to client 127.0.0.1:51828
2014-06-09 22:38:11 1   I received response from external application /path/to/myserver.sh for client 127.0.0.1:51828
server <3971>, response to request <myrequest2>
2014-06-09 22:38:11 1   I sending response to client 127.0.0.1:51828
2014-06-09 22:38:11 0   I detected EOF from external application /path/to/myserver.sh for client 127.0.0.1:51828
2014-06-09 22:38:11 0   I closing external application /path/to/myserver.sh for client 127.0.0.1:51828
2014-06-09 22:38:11 0   I closing connection to client 127.0.0.1:51828
^C2014-06-09 22:38:21 0   I received signal SIGINT
2014-06-09 22:38:21 0   I stop [3959]
Client 1 Side (without -1 option)
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest1
server <3966>
server <3966>, response to request <myrequest1>
Connection closed by foreign host.
Client 1 Side (without -1 option)
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest2
server <3971>
server <3971>, response to request <myrequest2>
Connection closed by foreign host.
Server Side with log enabled
$ mysvcd -l -1 -s /path/to/myserver.sh
2014-06-09 22:50:46 0   I start [4111]
2014-06-09 22:50:47 0   I server 192.168.0.104:1036
2014-06-09 22:50:53 0   I opening connection to client 127.0.0.1:52322
2014-06-09 22:50:53 0   I waiting for request from client 127.0.0.1:52322
2014-06-09 22:50:58 0   I received request from client 127.0.0.1:52322
myrequest3
2014-06-09 22:50:58 0   I executing external application /path/to/myserver.sh
2014-06-09 22:50:58 0   I sending response to client 127.0.0.1:52322
server <4115>
server <4115>, response to request <myrequest3>
2014-06-09 22:50:58 0   I closing connection to client 127.0.0.1:52322
2014-06-09 22:51:02 0   I received request from client 127.0.0.1:52322
myrequest4
2014-06-09 22:51:02 0   I executing external application /path/to/myserver.sh
2014-06-09 22:51:02 0   I sending response to client 127.0.0.1:52322
server <4116>
server <4116>, response to request <myrequest4>
2014-06-09 22:51:02 0   I closing connection to client 127.0.0.1:52322
2014-06-09 22:51:37 0   I detected EOF from client 127.0.0.1:52322
2014-06-09 22:51:37 0   I closing connection to client 127.0.0.1:52322
2014-06-09 22:51:43 0   I opening connection to client 127.0.0.1:52327
2014-06-09 22:51:43 0   I waiting for request from client 127.0.0.1:52327
2014-06-09 22:51:55 0   I received request from client 127.0.0.1:52327
myrequest5
2014-06-09 22:51:55 0   I executing external application /path/to/myserver.sh
2014-06-09 22:51:55 0   I sending response to client 127.0.0.1:52327
server <4125>
server <4125>, response to request <myrequest5>
2014-06-09 22:51:55 0   I closing connection to client 127.0.0.1:52327
2014-06-09 22:52:00 0   I received request from client 127.0.0.1:52327
myrequest6
2014-06-09 22:52:00 0   I executing external application /path/to/myserver.sh
2014-06-09 22:52:00 0   I sending response to client 127.0.0.1:52327
server <4126>
server <4126>, response to request <myrequest6>
2014-06-09 22:52:00 0   I closing connection to client 127.0.0.1:52327
^C2014-06-09 22:52:09 0   I received signal SIGINT
2014-06-09 22:52:09 0   I stop [4111]
Client 1 Side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest3
server <4115>
server <4115>, response to request <myrequest3>
myrequest4
server <4116>
server <4116>, response to request <myrequest4>
^]
telnet> quit
Connection closed.
Client 2 Side
telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
myrequest5
server <4125>
server <4125>, response to request <myrequest5>
myrequest6
server <4126>
server <4126>, response to request <myrequest6>
Connection closed by foreign host.

Web Server

Usage
  mysvcd -w [-1] [-l|-d [-l -o <logfile>] [-L <loglevels>]] [-p <port>] [-D] /path/to/(server|root)
    (if server is specified put on server stdin HTTP GET or POST requests from client
     get from server stdout HTTP responses for client,
     if root is specified return to clients server files corresponding to HTTP requests)

There are two ways of usage:

  1. if /path/to/server is specified a single application handling as CGI all HTTP client requests

  2. if /path/to/root is specified the resources related to HTTP client requests are retrieved on filesystem under this root directory or obtained as output of resource if it is related to an external executable application else obtained as output of internal expect procedure with same resource name

Only GET and POST method supported.

Handled file types for first usage mode:

  • .html files are returned to client with MIME type "text/html"

  • .gif files are returned to client with MIME type "image/gif" and are encoded using base64

  • .jpeg files are returned to client with MIME type "image/jpeg" and are encoded using base64

  • .txt files are returned to client with MIME type "text/plain"

  • .xml files are returned to client with MIME type "text/xml"

  • other files are return to client with MIME type "application/octet-stream" (useful to download a file from server)

Supported CGI variables setted by the server for second usage mode:

  • REQUEST_METHOD (set as GET or POST)

  • QUERY_STRING (only for GET)

  • CONTENT_LENGTH (only for POST)

  • REQUEST_URI (for GET and POST)

  • PATH_INFO (for GET and POST)

  • REMOTE_ADDR (for GET and POST)

  • SOAP_ACTION (for POST)

/path/to/root:

Server Side with log enabled (without -1 option)
$ mysvcd -l -w /path/to/root
2014-06-19 23:43:37 0   I start [7297]
2014-06-19 23:43:37 0   I server 192.168.0.105:1036
2014-06-19 23:43:41 0   I opening connection to client 127.0.0.1:55438
2014-06-19 23:43:50 0   I received request from client 127.0.0.1:55438
GET /index.html HTTP/1.0
2014-06-19 23:43:50 0   I sending response to client 127.0.0.1:55438
2014-06-19 23:43:50 0   I closing connection to client 127.0.0.1:55438
Client Side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
^]
telnet> quit
Connection closed.

/path/to/server:

myserver.sh
#!/bin/sh

echo "Content-Type: text/xml"
echo ""
echo "<?xml version=\"1.0\"?>"
echo "<instance>$$</instance>"
echo "<service>"
echo "<input>"
cat
echo "</input>"
echo "<query_string><![CDATA[${QUERY_STRING}]]><query_string>"
echo "<output>this is the output response</output>"
echo "</service>"
Server Side with log enabled (without -1 option)
$ mysvcd -l -w /path/to/myserver.sh
2014-06-22 15:23:13 0   I start [60186]
2014-06-22 15:23:13 0   I server 192.168.0.105:1036
2014-06-22 15:23:16 0   I opening connection to client 127.0.0.1:63531
2014-06-22 15:23:21 0   I received request from client 127.0.0.1:63531
GET /my/path?p1=A&p2=B HTTP/1.0
HEADER_1: 11
HEADER_2: 22
2014-06-22 15:23:25 0   I executing server /path/to/myserver.sh
2014-06-22 15:23:25 0   I GET request method
p1=A&p2=B
2014-06-22 15:23:25 0   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 0   I waiting for request from client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
Content-Type: text/xml
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531

2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<?xml version="1.0"?>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<instance>60191</instance>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<service>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<input>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
GET /my/path?p1=A&p2=B HTTP/1.0
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
HEADER_1: 11
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
HEADER_2: 22
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
</input>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<query_string><![CDATA[p1=A&p2=B]]><query_string>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
<output>this is the output response</output>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 1   I received response from server for client 127.0.0.1:63531
</service>
2014-06-22 15:23:25 1   I sending response to client 127.0.0.1:63531
2014-06-22 15:23:25 0   I detected EOF from server for client 127.0.0.1:63531
2014-06-22 15:23:25 0   I closing server for client 127.0.0.1:63531
2014-06-22 15:23:25 0   I closing connection to client 127.0.0.1:63531
2014-06-22 15:24:13 0   I opening connection to client 127.0.0.1:63587
2014-06-22 15:24:52 0   I received request from client 127.0.0.1:63587
POST /my/path2 HTTP/1.0
HEADER_3: 33
HEADER_4: 44
Content-Length: 20
2014-06-22 15:26:30 0   I executing cgi /path/to/myserver.sh
2014-06-22 15:26:30 0   I POST request method
p1=C&p2=D&p3=E&p4=FG
2014-06-22 15:26:30 0   I waiting for request from client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
Content-Type: text/xml
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587

2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<?xml version="1.0"?>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<instance>60364</instance>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<service>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<input>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
POST /my/path2 HTTP/1.0
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
HEADER_3: 33
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
HEADER_4: 44
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
Content-Length=20
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587

2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
p1=C&p2=D&p3=E&p4=FG
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
</input>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<query_string><![CDATA[p1=C&p2=D&p3=E&p4=FG]]><query_string>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
<output>this is the output response</output>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 1   I received response from server for client 127.0.0.1:63587
</service>
2014-06-22 15:26:30 1   I sending response to client 127.0.0.1:63587
2014-06-22 15:26:30 0   I detected EOF from server for client 127.0.0.1:63587
2014-06-22 15:26:30 0   I closing server for client 127.0.0.1:63587
2014-06-22 15:26:30 0   I closing connection to client 127.0.0.1:63587
^C2014-06-22 15:27:19 0   I received signal SIGINT
2014-06-22 15:27:19 0   I stop [60186]
Client 1 Side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
GET /my/path?p1=A&p2=B HTTP/1.0
HEADER_1: 11
HEADER_2: 22

HTTP/1.0 200 OK
Content-Type: text/xml

<?xml version="1.0"?>
<instance>60191</instance>
<service>
<input>
GET /my/path?p1=A&p2=B HTTP/1.0
HEADER_1: 11
HEADER_2: 22
</input>
<query_string><![CDATA[p1=A&p2=B]]><query_string>
<output>this is the output response</output>
</service>
Connection closed by foreign host.
Client 2 Side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
POST /my/path2 HTTP/1.0
HEADER_3: 33
HEADER_4: 44
Content-Length: 20

p1=C&p2=D&p3=E&p4=FG
HTTP/1.0 200 OK
Content-Type: text/xml

<?xml version="1.0"?>
<instance>60364</instance>
<service>
<input>
POST /my/path2 HTTP/1.0
HEADER_3: 33
HEADER_4: 44
Content-Length: 20

p1=C&p2=D&p3=E&p4=FG
</input>
<query_string><![CDATA[p1=C&p2=D&p3=E&p4=FG]]><query_string>
<output>this is the output response</output>
</service>
Connection closed by foreign host.

Expect Server

Internal:

Usage
  mysvcd -e [-1] [-l|-d [-l -o <logfile>] [-L <loglevels>]] [-p <port>] [-q "<queues>"] [-u "<users>"] -f <configfile> -c <configproc>
    (expect based server where client requests are calling to expect procedures
     configured on expect script <configfile> with <configproc> being an expect procedure
     inside <configfile> returing a list of <name,value> configuration parameters
     where expect procedure output is returned to client and by default
     using "kill -9 SIGUSR1 <pid>" the configuration file is reloaded and
     using "kill -9 SIGUSR2 <pid>" the server status is swapped from ON to OFF)

External:

Usage
  mysvcd -x [-1] [-l|-d [-l -o <logfile>] [-L <loglevels>]] [-p <port>] [-q "<queues>"] [-u "<users>"] -f <configfile> -c <configproc>
    (expect based server where client requests are calling to expect procedures
     configured on expect script <configfile> with <configproc> being an expect procedure
     inside <configfile> returing a list of <name,value> configuration parameters
     where the expect procedures return the path of an external command to execute
     whose standard output is returned to client and by default
     using "kill -9 SIGUSR1 <pid>" the configuration file is reloaded and
     using "kill -9 SIGUSR2 <pid>" the server status is swapped from ON to OFF)
  • The protocol used is the Expect language

  • With the "internal" server (option -e) is returned to client the output of Expect procedures

  • With the "external" server (option -r) is returned to client the output of external commands whose path must be returned by Expect procedures

  • The configuration file, specified with option <configfile> is itself an Expect script executed by the server

    • on startup and

    • on demand, when it receive the signal SIGUSR1

  • The configuration handler, specified with option <configproc> is the name of an Expect procedure (inside <configfile>) that must return a list of key-value pairs (the order is not relevant) e.g.:

    ...
    proc myConfigHandler {} {
      return {
        key1 value1
        key2 value2
        ...
        keyN valueN
      }
    }
    ...
  Each key is a configuration parameter
  (with its value)
- The main predefined configuration parameters are
  the following:
    enabledcommands
    users
    userenabledcommands
- Others configuration parameters:
    clienthandlers
    serverhandlers
    starthandler
    stophandler
    signalhandler
    resourcehandler
    log
    logenabler
    logfile
    loglevels
    eof
    serial
    server
    queues
    status
  • "enabledcommands": its value is the list of enabled commands Each command is an Expect procedure (inside <configfile>) that each client can execute If the value is "*" then all commands are enabled (is used a safe interpreter which for default has a minimal set of enabled commands) e.g.:

    ...
    proc myCommand1 {args1} {
      ...
    }
    ...
    proc myCommand2 {args2} {
      ...
    }
    ...
    proc myConfigHandler {} {
      return {
      ...
        enabledcommands {
          ...
          myCommand1
          myCommand2
          ...
        }
      ...
      }
    }
    ...
  • "clienthandlers": its value is a list of three procedures, the handler for open, read, close and error (the last is optional, the order is relevant)

    ...
    proc myClientOpenHandler {in out client} {
      ...
      ;# called when a client open the connection
      ;# (client is <clientaddr>:<clientport>)
      ;# to read from client use in
      ;# to write to client use out
      ;# must return:
      ;#   (*) 1 if the connection can be accepted
      ;#   (*) 0 elsewhere
      ;# useful to handle client authentication
      ...
    }
    ...
    proc myClientReadHandler {in out client request} {
      ...
      ;# called each time a client send a
      ;# request (a single line);
      ;# the predefined read handler
      ;# (handleClientRead)
      ;# wait for a complete command and
      ;# execute it as Expect procedure (if exists)
      ;# or as input for external command mysvc
      ...
    }
    ...
    proc myClientCloseHandler {in out client} {
    ...
      ;# executed when a client close
      ;# the connection
      ;# the default (handleClientClose)
      ;# is empty
    ...
    }
    ...
    proc myClientExecHandler {in out client command} {
    ...
      ;# to handle expect procedure execution
      ;# the default (handleClientExec)
      ;#   (*) return procedure output to client if serial option is set
      ;#   (*) execute the external command specified by procedure output
      ;#       elsewhere, sending:
      ;#         (*) partial external procedure output to client if flush option is set
      ;#         (*) complete external procedure output to client elsewhere
      ;# the predefined mysvc procedure execute the $MYSVC_HOME/bin/mysvc external command
    ...
    }
    ...
    proc myConfigHandler {} {
      return {
      ...
        clienthandlers {
          myClientOpenHandler
          myClientReadHandler
          myClientCloseHandler
          myClientExecHandler
        }
      ...
      }
    }
    ...
  • "serverhandlers": its value is a list of three procedures, the handler for open, read and close

    ...
    proc myServerOpenHandler {inout server} {
      ...
      ;# called when connect is called
      ;# (server is <serveraddr>:<serverport>)
      ;# to read from or write to server
      ;# use inout
      ;# must return:
      ;#   (*) 1 if the connection can be accepted
      ;#   (*) 0 elsewhere
      ...
    }
    ...
    proc myServerReadHandler {inout response server} {
      ...
      ;# called each time a server send a
      ;# response (a single line);
      ;# the predefined read handler
      ;# (handleServerRead) handle mysvcd
      ;# as a client instead of as a server
      ...
    }
    ...
    proc myServerCloseHandler {inout server} {
    ...
      ;# executed when a server close
      ;# the connection
      ;# the default (handleServerClose)
      ;# is empty
    ...
    }
    ...
    proc myConfigHandler {} {
      return {
      ...
        serverhandlers {
          myServerOpenHandler
          myServerReadHandler
          myServerCloseHandler
        }
      ...
      }
    }
    ...
  • "starthandler": its value is the name of a procedure called when the server is started

  ...
  proc myStartHandler {} {
    ;# ...
    ;# handle server start
    ;# ...
  }
  ...
  proc myConfigHandler {} {
    return {
    ...
      starthandler myStartHandler
    ...
    }
  }
  ...
  • "stophandler": its value is the name of a procedure called when the server is stopped

  ...
  proc myStopHandler {} {
    ;# ...
    ;# handle server stop
    ;# ...
  }
  ...
  proc myConfigHandler {} {
    return {
    ...
      stophandler myStopHandler
    ...
    }
  }
  ...
  • "signalhandler": its value is the name of a procedure that handle the USR2 signal

    ...
    proc mySignalHandler {} {
      ...
      ;# the predefined signal handler
      ;# (handleSignal) call switchStatus
      ;# that switch the server status
      ;# between on and off
      ;# (if status is off the server
      ;#  don't accept any new client
      ;#  connection)
      ...
    }
    ...
    proc myConfigHandler {} {
      return {
      ...
        signalhandler mySignalHandler
      ...
      }
    }
    ...
  • "resourcehandler": its value is the name of a procedure that handle the resource when mysvcd is used as HTTP server and a "GET <resource>" request is received by a client

    ...
    proc myResourceHandler {in out client resource} {
      ;# ...
      ;# return (filtered) resource to client
      ;# ...
    }
    ...
    proc myConfigHandler {} {
      return {
      ...
        resourcehandler myResourceHandler
      ...
      }
    }
    ...
  • "queues": its value is a list containing a pair of directory: the queue input directory and the queue output directory (default values are $MYSVC_HOME/in and $MYSVC_HOME/out)

    ...
    proc myConfigHandler {} {
      return {
      ...
        queues {
          "/my/path/to/queue/inputdir"
          "/my/path/to/queue/outputdir"
        }
      ...
      }
    }
    ...
  • "users": its value is a list of username/password pairs:

    ...
    proc myConfigHandler {} {
      return {
      ...
        users {
          username1/password1
          username2/password2
          ...
          usernameN/passwordN
        }
      ...
      }
    }
    ...
  • "userenabledcommands": its value is a list of pairs; each pair is a username followed by a list ef enabled commands for that user Note: regular expressions can be used as enabled commands

    ...
    proc myConfigHandler {} {
      return {
      ...
        userenabledcommands {
          username1 {
            enabledcommand11
            enabledcommand12
            ...
            enabledcommand1N
          }
          username2 {
            enabledcommand21
            enabledcommand22
            ...
            enabledcommand2N
          }
          ...
          usernameM {
            enabledcommandM1
            enabledcommandM2
            ...
            enabledcommandMN
          }
        }
      ...
      }
    }
    ...
  • "server": its value is the id of server when mysvcd is used as client

    ...
    proc myConfigHandler {} {
      return {
      ...
        server <serveraddr>[:<serverport>]
      ...
      }
    }
    ...
  • "log": its value can be: 1 if log is enabled 0 elsewhere (the predefined value is 0) to change its value you can use the command log [1|0] (with no argument the actual value is returned)

    ...
    proc myConfigHandler {} {
      return {
      ...
        log 1
      ...
      }
    }
    ...
  • "logenabler": its value is the name of a procedure that must enable a log the default procedure (logEnabler) enable a log iff its level is into one of <loglevels> parameter

    ...
    proc myLogEnabler {level type text} {
      ...
      # must return:
      #   1 if log is enabled
      #   0 elsewhere
      ...
    }
    ...
    proc myConfigHandler {} {
      ...
        logenabler myLogEnabler
      ...
    }
    ...
  • "logfile": its value is the name of log file (same as <logfile> command line option)

    ...
    proc myConfigHandler {} {
      return {
      ...
        logfile "/my/path/to/logfile"
      ...
      }
    }
    ...
  • "loglevels": its value is a list of (comma separated) log items, where each log item is a single log level or a range of log levels (same as <loglevels> command line option) <loglevels> ::= <logitem>","…","<logitem> <logitem> ::= <loglevel> | <logrange> <loglevel> ::= 0…999

    ...
    proc myConfigHandler {} {
      return {
      ...
        loglevels "0-8,12,24-32,128-134,138"
      ...
      }
    }
    ...
  • "eof": its value is a regular expression; used into "test" mode (-t flag specified); if input (read from stdin) match this regular expression, then the connection with client is closed default value is {^\.$}

    ...
    proc myConfigHandler {} {
      return {
      ...
        eof {^EOF$}
      ...
      }
    }
    ...
  • "serial": its value can be: 1 if the server is serial 0 elsewhere (the predefined value is 0) (same as -1 command line option) if server is not serial can handle more client together

    ...
    proc myConfigHandler {} {
      return {
      ...
        serial 1
      ...
      }
    }
    ...
  • "status": its value can be: 1 if the server accept client connections 0 elsewhere (the predefined value is 1) to change its value you can use the command status [1|0] (with no argument the actual value is returned)

    ...
    proc myConfigHandler {} {
      return {
      ...
        status 0
      ...
      }
    }
    ...
mysvcd.conf
proc mysvc_myservice1 {{config {}} {input {}} {username {}} {password {}}} {
  return [mysvc myservice1 $config $input $username $password]
}

proc mysvc_myservice2 {{config {}} {input {}} {username {}} {password {}}} {
  return [mysvc myservice2 $config $input $username $password]
}

proc mysvc_myservice3 {{config {}} {input {}} {username {}} {password {}}} {
  return "ls -lrt"
}

proc mysvc_myservice4 {{config {}} {input {}} {username {}} {password {}}} {
  return "output of mysvc_myservice4 to input <$input>"
}

proc mysvc_myservice5 {{config {}} {input {}} {username {}} {password {}}} {
  return "output of mysvc_myservice5 to input <$input>"
}

proc mysvc.config {} {
  return {
    enabledcommands {
      mysvc
      mysvc_myservice1
      mysvc_myservice2
      mysvc_myservice3
      mysvc_myservice4
      mysvc_myservice5
    }

    users {
      mysvcadm/mysvcadm01
      mysvcusr1/mysvcusr01
      mysvcusr2/mysvcusr02
      mysvcusr3/mysvcusr03
    }

    userenabledcommands {
      mysvcadm {
        mysvc
        mysvc_myservice1
        mysvc_myservice2
        mysvc_myservice3
        mysvc_myservice4
        mysvc_myservice5
      }
      mysvcusr1 {
        mysvc_myservice1
      }
      mysvcusr2 {
        mysvc_myservice2
      }
      mysvcusr3 {
        mysvc_myservice3
        mysvc_myservice4
        mysvc_myservice5
      }
    }
  }
}

login with wrong password:

Server side with log enabled
$ mysvcd -e -l -f mysvcd.conf -c mysvc.config
2014-06-27 22:17:18 0   I start [4683]
2014-06-27 22:17:18 0   I server 192.168.0.105:1036
2014-06-27 22:17:24 0   I opening connection to client 127.0.0.1:56983
2014-06-27 22:17:24 0   I waiting for request from client 127.0.0.1:56983
2014-06-27 22:17:37 0   I received request from client 127.0.0.1:56983
login mysvcusr3/mysvcusr00
2014-06-27 22:17:37 0   I login request received
2014-06-27 22:17:37 0   W login mysvcusr3/mysvcusr00 refused
2014-06-27 22:17:37 0   W invalid username or password mysvcusr3/mysvcusr00
2014-06-27 22:17:37 0   I sending NACK to client 127.0.0.1:56983
2014-06-27 22:17:37 0   I closing connection to client 127.0.0.1:56983
Client side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
login mysvcusr3/mysvcusr00
1
Connection closed by foreign host.

Internal:

Server side with log enabled
$ mysvcd -e -l -f mysvcd.conf -c mysvc.config
2014-06-27 22:20:27 0   I start [4851]
2014-06-27 22:20:27 0   I server 192.168.0.105:1036
2014-06-27 22:20:30 0   I opening connection to client 127.0.0.1:57145
2014-06-27 22:20:30 0   I waiting for request from client 127.0.0.1:57145
2014-06-27 22:20:38 0   I received request from client 127.0.0.1:57145
login mysvcusr3/mysvcusr03
2014-06-27 22:20:38 0   I login request received
2014-06-27 22:20:38 0   I login mysvcusr3/mysvcusr03 accepted
2014-06-27 22:20:38 0   I sending ACK to client 127.0.0.1:57145
2014-06-27 22:21:54 0   I received request from client 127.0.0.1:57145
mysvc_myservice3 myconfig myinput myusername mypassword
2014-06-27 22:21:54 0   I command mysvc_myservice3 enabled to user mysvcusr3
2014-06-27 22:21:54 0   I sending ACK to client 127.0.0.1:57145
mysvc_myservice3 myconfig myinput myusername mypassword
2014-06-27 22:21:54 0   I sending response to client 127.0.0.1:57145
ls -lrt
2014-06-27 22:22:24 0   I received request from client 127.0.0.1:57145
logout
2014-06-27 22:22:24 0   I logout request received
2014-06-27 22:22:24 0   I sending ACK to client 127.0.0.1:57145
2014-06-27 22:22:24 0   I closing connection to client 127.0.0.1:57145
Client side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
login mysvcusr3/mysvcusr03
0
mysvc_myservice3 myconfig myinput myusername mypassword
0
ls -lrt
.
logout
0
Connection closed by foreign host.

External:

Server side with log enabled
$ mysvcd -r -l -f mysvcd.conf -c mysvc.config
2014-06-27 22:24:53 0   I start [5039]
2014-06-27 22:24:53 0   I server 192.168.0.105:1036
2014-06-27 22:24:56 0   I opening connection to client 127.0.0.1:57372
2014-06-27 22:24:56 0   I waiting for request from client 127.0.0.1:57372
2014-06-27 22:25:01 0   I received request from client 127.0.0.1:57372
login mysvcusr3/mysvcusr03
2014-06-27 22:25:01 0   I login request received
2014-06-27 22:25:01 0   I login mysvcusr3/mysvcusr03 accepted
2014-06-27 22:25:01 0   I sending ACK to client 127.0.0.1:57372
2014-06-27 22:25:27 0   I received request from client 127.0.0.1:57372
mysvc_myservice3 myconfig myinput myusername mypassword
2014-06-27 22:25:27 0   I command mysvc_myservice3 enabled to user mysvcusr3
2014-06-27 22:25:27 0   I sending ACK to client 127.0.0.1:57372
mysvc_myservice3 myconfig myinput myusername mypassword
2014-06-27 22:25:27 0   I executing external command for client 127.0.0.1:57372
ls -lrt
2014-06-27 22:25:27 1   I received response from command mysvc_myservice3 for client 127.0.0.1:57372
total 15
2014-06-27 22:25:27 1   I received response from command mysvc_myservice3 for client 127.0.0.1:57372
2014-06-27 22:25:27 1   I received response from command mysvc_myservice3 for client 127.0.0.1:57372
2014-06-27 22:25:27 1   I received response from command mysvc_myservice3 for client 127.0.0.1:57372
2014-06-27 22:25:27 0   I detected EOF from command mysvc_myservice3 for client 127.0.0.1:57372
2014-06-27 22:25:27 1   I sending response to client 127.0.0.1:57372
2014-06-27 22:25:27 0   I closing command mysvc_myservice3 for client 127.0.0.1:57372
2014-06-27 22:25:31 0   I received request from client 127.0.0.1:57372
logout
2014-06-27 22:25:31 0   I logout request received
2014-06-27 22:25:31 0   I sending ACK to client 127.0.0.1:57372
2014-06-27 22:25:31 0   I closing connection to client 127.0.0.1:57372
Client side
$ telnet 0 1036
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
login mysvcusr3/mysvcusr03
0
mysvc_myservice3 myconfig myinput myusername mypassword
0
total 30
-rwxr-xr-x  1 davide  staff    10 Jun 25  2012 file1
-rwxr-xr-x  1 davide  staff     5 Jun 25  2012 file2
-rw-r--r--  1 davide  staff    15 Jun 25  2012 file3
.
logout
0
Connection closed by foreign host.

Proxy Server

Usage
  mysvcd -x [-l|-d [-l -o <logfile>] [-L <loglevels>]] [-p <port>] -f <configfile> -c <configproc> <host>[:<port>]
    (run as proxy server from clients and remote server <host>:<port>,
     if <port> is not specified then default port is used)
Server side with log enabled
$ mysvcd -l -w /path/to/myserver.sh
2014-06-22 21:55:27 0   I start [9221]
2014-06-22 21:55:27 0   I server 192.168.0.105:1036
2014-06-22 21:56:56 0   I opening connection to client 127.0.0.1:62440
2014-06-22 21:57:05 0   I received request from client 127.0.0.1:62440
GET /my/path?p1=A&p2=B HTTP/1.0
XX:1
YY:2
2014-06-22 21:57:33 0   I executing server /path/to/myserver.sh
2014-06-22 21:57:33 0   I GET request method
p1=A&p2=B
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 0   I waiting for request from client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
Content-Type: text/xml
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440

2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<?xml version="1.0"?>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<instance>9381</instance>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<service>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<input>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
GET /my/path?p1=A&p2=B HTTP/1.0
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
XX:1
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
YY:2
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
</input>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<query_string><![CDATA[p1=A&p2=B]]><query_string>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
<output>this is the output response</output>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 1   I received response from server for client 127.0.0.1:62440
</service>
2014-06-22 21:57:33 1   I sending response to client 127.0.0.1:62440
2014-06-22 21:57:33 0   I detected EOF from server for client 127.0.0.1:62440
2014-06-22 21:57:33 0   I closing server for client 127.0.0.1:62440
2014-06-22 21:57:33 0   I closing connection to client 127.0.0.1:62440
Proxy Side
$ mysvcd -x -l -p 1037 0:1036
2014-06-22 21:56:39 0   I start [9303]
2014-06-22 21:56:39 0   I server 192.168.0.105:1037
2014-06-22 21:56:56 0   I opening connection to client 127.0.0.1:62439
2014-06-22 21:56:56 0   I opening connection to server 0:1036
2014-06-22 21:56:56 0   I waiting for request from client 127.0.0.1:62439
2014-06-22 21:57:05 0   I received request from client 127.0.0.1:62439
GET /my/path?p1=A&p2=B HTTP/1.0
2014-06-22 21:57:05 0   I sending request to server 0
2014-06-22 21:57:08 0   I received request from client 127.0.0.1:62439
XX:1
2014-06-22 21:57:08 0   I sending request to server 0
2014-06-22 21:57:12 0   I received request from client 127.0.0.1:62439
YY:2
2014-06-22 21:57:12 0   I sending request to server 0
2014-06-22 21:57:33 0   I received request from client 127.0.0.1:62439

2014-06-22 21:57:33 0   I sending request to server 0
2014-06-22 21:57:33 0   I received response from server 0:1036
HTTP/1.0 200 OK
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
Content-Type: text/xml
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036

2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<?xml version="1.0"?>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<instance>9381</instance>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<service>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<input>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
GET /my/path?p1=A&p2=B HTTP/1.0
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
XX:1
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
YY:2
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
</input>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<query_string><![CDATA[p1=A&p2=B]]><query_string>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
<output>this is the output response</output>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036
</service>
2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I received response from server 0:1036

2014-06-22 21:57:33 0   I sending response to client 127.0.0.1:62439
2014-06-22 21:57:33 0   I closing connection to server 0:1036
2014-06-22 21:57:33 0   I closing connection to client 127.0.0.1:62439
Client Side
$ telnet 0 1037
Trying 0.0.0.0...
Connected to 0.
Escape character is '^]'.
GET /my/path?p1=A&p2=B HTTP/1.0
XX:1
YY:2

HTTP/1.0 200 OK
Content-Type: text/xml

<?xml version="1.0"?>
<instance>9381</instance>
<service>
<input>
GET /my/path?p1=A&p2=B HTTP/1.0
XX:1
YY:2
</input>
<query_string><![CDATA[p1=A&p2=B]]><query_string>
<output>this is the output response</output>
</service>

Connection closed by foreign host.

Using mysvcd as client

Generic Client

Usage
  mysvcd [-l|-d [-l -o <logfile>] [-L <loglevels>]] [-p <port>] <host>[:<port>]
    (run as client for remote server <host>:<port>)
  • client standard input is sent as input to server

  • server output is sent to client standard output

Server Side with log enabled
$ mysvcd -l -w /path/to/myserver.sh
2014-06-22 22:14:24 0   I start [10282]
2014-06-22 22:14:24 0   I server 192.168.0.105:1036
2014-06-22 22:14:27 0   I opening connection to client 127.0.0.1:63146
2014-06-22 22:14:32 0   I received request from client 127.0.0.1:63146
GET /my/path?p1=A&p2=B HTTP/1.0
XX: 3
YY: 4
2014-06-22 22:14:34 0   I executing server /path/to/myserver.sh
2014-06-22 22:14:34 0   I GET request method
p1=A&p2=B
2014-06-22 22:14:34 0   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 0   I waiting for request from client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
Content-Type: text/xml
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146

2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<?xml version="1.0"?>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<instance>10288</instance>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<service>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<input>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
GET /my/path?p1=A&p2=B HTTP/1.0
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
XX: 3
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
YY: 4
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
</input>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<query_string><![CDATA[p1=A&p2=B]]><query_string>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
<output>this is the output response</output>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 1   I received response from server for client 127.0.0.1:63146
</service>
2014-06-22 22:14:34 1   I sending response to client 127.0.0.1:63146
2014-06-22 22:14:34 0   I detected EOF from server for client 127.0.0.1:63146
2014-06-22 22:14:34 0   I closing server for client 127.0.0.1:63146
2014-06-22 22:14:34 0   I closing connection to client 127.0.0.1:63146
Client Side
$ cat | mysvcd 0:1036
GET /my/path?p1=A&p2=B HTTP/1.0
XX: 3
YY: 4

HTTP/1.0 200 OK
Content-Type: text/xml

<?xml version="1.0"?>
<instance>10288</instance>
<service>
<input>
GET /my/path?p1=A&p2=B HTTP/1.0
XX: 3
YY: 4
</input>
<query_string><![CDATA[p1=A&p2=B]]><query_string>
<output>this is the output response</output>
</service>

^C