botsense  3.2.0
RoadNarrows Client-Server Proxied Services Framework
loopback.sh
1 #!/bin/bash
2 #
3 # Quick, down and dirty test of bsProxy server using loopbacks.
4 #
5 # Hard coded message format:
6 #
7 # HDR
8 # ---
9 # 2 magic aa aa
10 # 1 tid 00
11 # 1 hnd fe = 254
12 # 2 msgid 00 03
13 # 2 blen 00 1f = 31
14 # --
15 # 8 byte
16 #
17 # BODY
18 # ---
19 # 2 msgid 00 03
20 # 1 fcnt 01
21 # 1 fid 01
22 # 1 ftype 73 = 's'
23 # 1 flen 19 = 25
24 # 25 fval 68 65 6c 6c 6f 20 30 20 66 72
25 # 6f 6d 20 6c 6f 6f 70 62 61 63
26 # 6b 2e 73 68 0a = "hello 0 from loopback.sh\n"
27 #
28 # --
29 # 31 bytes
30 
31 MAGIC='\xaa\xaa'
32 HND_SERVER='\xfe'
33 REQ_LOOPBACK='\x00\x03'
34 
35 FIXED="${REQ_LOOPBACK}\x01"
36 FID='\x01'
37 FTYPE='s'
38 
39 cnt=0
40 
41 while :
42 do
43  sleep 1
44 
45  cdata="hello ${cnt} from loopback.sh" # loop this back
46  let len=${#cdata}+1 # length including newline
47  flen="\x"$(printf "%02x" ${len}) # hex field length
48 
49  tid="\x"$(printf "%02x" ${cnt}) # hex tid
50  let len=3+3+${len} # total body length
51  blen="\x00\x"$(printf "%02x" ${len}) # hex body length
52 
53  hdr="${MAGIC}${tid}${HND_SERVER}${REQ_LOOPBACK}${blen}"
54  body="${FIXED}${FID}${FTYPE}${flen}${cdata}"
55 
56  echo -e "${hdr}${body}" >&3
57  read line <&3
58 
59  #printf "msgid=0x%02x, tid=%u, blen=%u: " ${line:0:1} ${line:1:1} ${line:2:1}
60  echo ${line:11}
61 
62  let cnt=${cnt}+1
63 done 3<>/dev/tcp/127.0.0.1/9195