added emulator and improve server to interoperate
[safeq] / terminal-emulator.pl
1 #!/usr/bin/perl
2 use warnings;
3 use strict;
4
5 use Data::Dump qw(dump);
6
7 use IO::Socket::INET;
8
9 my $ip   = shift @ARGV || '127.0.0.1';
10 my $port = shift @ARGV || 4096;
11
12 my $socket = IO::Socket::INET->new(
13         PeerAddr => $ip,
14         PeerPort => $port,
15         Proto => 'tcp',
16 ) or die "ERROR $ip:$port - $!";
17
18 warn "# connected to $ip:$port\n";
19
20 my @send_receive = grep { /^.+$/ } split(/\n/, q{
21 .SQ 3.2.9 SQPR8463332F62E
22 .SQ OK
23
24 .CFG gd lang=HR
25 .CFG OK %s
26
27 .SERVER LIST
28 .ERROR NO-ENTERPRISE
29
30 .CARD E009000000009999
31 .CARD OK Ime Prezime (nobody@example.com)
32
33 .ACTION
34 .ACTION CMENUS0
35
36 .NOP
37 .NOP 
38
39
40 .NOP
41 .NOP 
42
43 .NOP
44 .NOP 
45
46 .NOP
47 .NOP 
48
49 .NOP
50 .NOP
51
52 .END 
53 });
54
55 #warn "# send_receive=",dump( \@send_receive );
56
57 while ( @send_receive ) {
58         my $send   = shift @send_receive;
59         my $expect = shift @send_receive;
60         warn ">> $send\n";
61         print $socket "$send\r\n";
62         my $got = <$socket>;
63         $got =~ s/[\r\n]+$//;
64 warn dump($send,$expect,$got);
65         warn "<< $got\n";
66         die "ERROR expected [$expect] got [$got]" if $expect ne $got;
67 }
68
69 $socket->close();