This commit is contained in:
2024-10-14 00:08:40 +02:00
parent dbfba56f66
commit 1462d52e13
4572 changed files with 2658864 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
#!C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp-gui.exe
PAP-Version: 1.0
Packer: C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp.exe
Script: uni-client-aw.pl
Cwd: G:\My Documents\Diverse Skripts\JSON Server Client\AW Client
Clean: 0
Date: 2011-03-18 07:43:04
Debug:
Dependent: 0
Dyndll: 0
Exe: uni-client.exe
Force: 0
Gui: 0
Hostname: neticfsys03
Manifest:
No-Compress: 0
No-Logo: 0
Runlib:
Shared: none
Tmpdir:
Verbose: 0
Version-Comments:
Version-CompanyName: ICF Systems AG
Version-FileDescription:
Version-FileVersion: 1.2
Version-InternalName: Universal Client
Version-LegalCopyright: Andre Wisniewski
Version-LegalTrademarks:
Version-OriginalFilename: uni-client.exe
Version-ProductName: Universal Client
Version-ProductVersion: 1.2
Warnings: 0
Xclude: 0

View File

@@ -0,0 +1,203 @@
#!/usr/bin/perl -X
use warnings;
use Thread;
use IO::Socket::Multicast;
use Win32::Console::ANSI qw /Cursor Title/;
use IO::Socket;
use JSON::XS;
use strict;
my %jdata :shared;
my %data;
my @sortedindex;
my $gotdata :shared;
my $rrthr :shared;
$rrthr = 0;
$gotdata=0;
#my $peerhost = "10.61.1.10";
my $peerhost;
my $peerport;
if ($ARGV[0] eq "") {
$peerhost="0.0.0.0"; $peerport="11211";
}
else {
if ($ARGV[1] eq "") { wrong_start("Kein Port"); }
my $e=$ARGV[1];
if ($e<1024 or $e>65535) {wrong_start("Ungültiger Port");}
$peerport = $e;
my ($a,$b,$c,$d) = split/\./,$ARGV[0];
if ($ARGV[0] eq "0.0.0.0") {
$peerhost=0.0.0.0;
}
else {
if ($a<1 or $a>255 or $b<0 or $b>255 or $c<0 or $c>255 or $d<1 or $d>255) { wrong_start("Ungültige IP"); }
$peerhost = $a . "." . $b . "." . $c . "." . "$d";
}
}
while (1) {
if ($rrthr==0) {
print "Receive JSON neu starten\n";
#<STDIN>;
my $thr = new Thread(\&ReceiveJSON);
$thr->detach;
#sleep 1;
}
if ($gotdata and $rrthr==1) {
TransformJSON();
@sortedindex=Sorted();
print "\e[2J";
my $status = $data{0}[0];
my $res1 = $data{0}[1];
my $res2 = $data{0}[2];
my $res3 = $data{0}[3];
my $timest = $data{0}[4];
my $spalten = $data{0}[5];
my $zeilen = $data{0}[6];
my $label = $data{0}[7];
my $showl = 0; # beschriftung wird angezeigt
$showl = 1 if ($label eq ""); # beschriftung wird nicht angezeigt
my $gesamtzeilen = @sortedindex;
my $startshow = 7 + $showl;
my $endshow;
if ($spalten eq "") {
$endshow=@{$data{0}} -1;
}
else {
$endshow = $startshow -1 + $spalten;
}
$zeilen=$gesamtzeilen if ($zeilen eq "");
#spaltenbreite ermitteln
my @sb;
for my $id (0 .. $zeilen -1) { #zeilen durchlaufen
my $i=$sortedindex[$id];
for my $c ($startshow .. $endshow) { #spalten durchlaufen
# spaltenbreite ist länge der aktuellen spalte wenn die aktuelle länger als die bisher ermittelte länge ist
$sb[$c]=0 unless ($sb[$c]);
$sb[$c] = length ($data{$i}[$c]) if (length ($data{$i}[$c]) > $sb[$c]);
}
}
for my $id (0 .. $zeilen -1) {
my $i=$sortedindex[$id];
for my $c ($startshow .. $endshow) {
# soviele leerzeichen schreiben bis die anzahl der geschriebenen leerzeichen + des inhalts die maximale länge der spalte erreicht hat
my $lenv;
if ($data{$i}[$c] eq "") {
$lenv=0;
}
else {
$lenv = length($data{$i}[$c]);
}
for (my $j=0;$j<$sb[$c]-$lenv;$j++) {
print " ";
}
# ein leerzeichen muß hinten angehängt werden damit eine lücke zwischen den spalten entsteht
printf "%s ", $data{$i}[$c];
}
print "\n" if ($id==0); # nach der überschrift eine leerzeile einfügen
print "\n"; # zeilenumbruch einfügen
}
}
sleep 1;
}
sub Sorted {
my @sorted;
my $type=0; # type 0 numerisch, 1 alphanumerisch
foreach (keys %data) {
if ($_ =~ /[a-z]/i) {
$type=1;
}
}
if ($type == 0) {
foreach my $id (sort { $a <=> $b } keys %data) {
push @sorted, $id;
}
}
else {
foreach my $id (sort keys %data) {
push @sorted, $id;
}
}
return @sorted;
}
sub ReceiveJSON {
my $JSONObject = JSON::XS->new->ascii->pretty->relaxed->allow_nonref();
$rrthr=1;
my $socket = new IO::Socket::INET (PeerAddr => $peerhost,
PeerPort => $peerport,
Proto => 'tcp',
) or $rrthr=0;
if ($rrthr==0) {
print "Keinen Server gefunden unter $peerhost:$peerport\n";
#<STDIN>;
return;
}
#$socket->send("\n");
#printf "[Connected to %s]\n", $socket->peerport;
while ( 1 ) {
my $recv_data;
if ($socket->peerport eq "") {
$rrthr=0;
#die "Verbindung zum Server verloren!\n";
#return;
print "Verbindung verloren\n";
#<STDIN>;
threads->exit();
}
$socket->send("GETDATA\n");
$socket->recv($recv_data,4096);
local $@;
my $failed=not eval {
%jdata = %{$JSONObject->decode($recv_data)};
return 1;
};
if ($failed) {
$gotdata=0;
#$rrthr=0;
#die "Malformed JSON\n";
#return;
print "Malformed JSON\n";
#<STDIN>;
#threads->exit();
}
$gotdata=1;
sleep 1;
}
}
sub TransformJSON {
foreach my $id (keys %jdata) {
my @fields = split /\|/,$jdata{$id};
#@arr=($a,$b,$c,$d);
#push @{$hash2{$_}}=@arr;
#$hash2{$_} = [$a, $b, $c ,$d];
$data{$id} = [@fields];
}
}
sub wrong_start {
print "\n\n\t$_[0]\n\nAufruf:\n\nmcastrcv3 [<IP> <PORT>]\n\nOhne Angabe von IP und Port wird auf 0.0.0.0 11211 verbunden\n\n";
exit;
}

Binary file not shown.

View File

@@ -0,0 +1,34 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# MC_ADDR:PORT
#Service ID 1
001:224.0.64.2:50001
001:224.0.65.2:50005
#Service ID 101
101:224.0.64.2:50002
101:224.0.65.2:50006
#Service ID 2
002:224.0.64.3:50001
002:224.0.65.3:50005
#Service ID 102
102:224.0.64.3:50002
102:224.0.65.3:50006
#Service ID 51
051:224.0.64.2:50003
051:224.0.65.2:50007
#Service ID 151
151:224.0.64.2:50004
151:224.0.65.2:50008
#Service ID 52
052:224.0.64.3:50003
052:224.0.65.3:50007
#Service ID 152
152:224.0.64.3:50004
152:224.0.65.3:50008

View File

@@ -0,0 +1,126 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# MC_ADDR:PORT
#Service ID 1
#Liffe 1:224.0.64.2:50001
#Liffe 1:224.0.65.2:50005
#Service ID 2
Liffe 2:224.0.64.3:50001
Liffe 2:224.0.65.3:50005
#Service ID 4
Liffe 4:224.0.64.5:50001
Liffe 4:224.0.65.5:50005
#Service ID 6
Liffe 6:224.0.64.7:50001
Liffe 6:224.0.65.7:50005
#Service ID 36
Liffe 36:224.0.64.8:50001
Liffe 36:224.0.65.8:50005
#Service ID 101
#Liffe 101:224.0.64.2:50002
#Liffe 101:224.0.65.2:50006
#Service ID 102
Liffe 102:224.0.64.3:50002
Liffe 102:224.0.65.3:50006
#Service ID 104
Liffe 104:224.0.64.5:50002
Liffe 104:224.0.65.5:50006
#Service ID 106
Liffe 106:224.0.64.7:50002
Liffe 106:224.0.65.7:50006
#Service ID 136
Liffe 136:224.0.64.8:50002
Liffe 136:224.0.65.8:50006
#Service ID 51
#Liffe 51:224.0.64.2:50003
#Liffe 51:224.0.65.2:50007
#Service ID 52
Liffe 52:224.0.64.3:50003
Liffe 52:224.0.65.3:50007
#Service ID 54
Liffe 54:224.0.64.5:50003
Liffe 54:224.0.65.5:50007
#Service ID 56a
Liffe 56a:224.0.64.7:50003
Liffe 56a:224.0.65.7:50007
#Service ID 56b
Liffe 56b:224.0.64.8:50003
Liffe 56b:224.0.65.8:50007
#Service ID 151
#Liffe 151:224.0.64.2:50004
#Liffe 151:224.0.65.2:50008
#Service ID 152
Liffe 152:224.0.64.3:50004
Liffe 152:224.0.65.3:50008
#Service ID 154
Liffe 154:224.0.64.5:50004
Liffe 154:224.0.65.5:50008
#Service ID 156a
Liffe 156a:224.0.64.7:50004
Liffe 156a:224.0.65.7:50008
#Service ID 156b
Liffe 156b:224.0.64.8:50004
Liffe 156b:224.0.65.8:50008
# Cash
#
#Cash 901:224.0.52.4:21028
#Cash 901:224.0.53.4:21029
#Cash 902:224.0.52.5:21030
#Cash 902:224.0.53.5:21031
#Cash 903:224.0.52.6:21032
#Cash 903:224.0.53.6:21033
#Cash 904:224.0.52.7:21034
#Cash 904:224.0.53.7:21035
#Cash 905:224.0.52.8:21036
#Cash 905:224.0.53.8:21037
#Cash 906:224.0.52.9:21038
#Cash 906:224.0.53.9:21039
#Cash 907:224.0.52.10:21040
#Cash 907:224.0.53.10:21041
#Cash 908:224.0.52.11:21042
#Cash 908:224.0.53.11:21043
#Cash 909:224.0.52.12:21044
#Cash 909:224.0.53.12:21045
#Cash 910:224.0.52.13:21046
#Cash 910:224.0.53.13:21047
#Cash 911:224.0.52.14:21048
#Cash 911:224.0.53.14:21049
#Cash 912:224.0.52.15:21050
#Cash 912:224.0.53.15:21051
#Cash 913:224.0.52.16:21052
#Cash 913:224.0.53.16:21053
#Cash 914:224.0.52.21:21062
#Cash 914:224.0.53.21:21063

View File

@@ -0,0 +1,17 @@
#!/bin/perl
$hash{0}="00|01|02|03";
$hash{1}="10|11|12|13";
$hash{2}="20|21|22|23";
$hash{3}="30|31|32|33";
foreach (keys %hash) {
($a,$b,$c,$d) = split /\|/,$hash{$_};
@arr=($a,$b,$c,$d);
#push @{$hash2{$_}}=@arr;
#$hash2{$_} = [$a, $b, $c ,$d];
$hash2{$_} = [@arr];
}
print %hash2;

View File

@@ -0,0 +1,137 @@
#!/bin/perl
use Thread;
use IO::Socket::Multicast;
use Win32::Console::ANSI qw /Cursor Title/;
use Term::ANSIScreen qw /:screen :cursor/;
use POE;
use POE::Component::Server::TCP;
use JSON::XS;
use strict;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my $thr;
my $TimeOut = 20;
my $starttime;
my %JSONdata :shared;
$thr = new Thread (\&Main);
#$data{"0"}="hallo0";
#$data{"1"}="hallo1";
TCPServer ();
POE::Kernel->run();
sub Main {
# Konfigdatei einlesen
open CONF, "<config.txt";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { $thr = new Thread (\&WaitForMessage,$_); }
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
while (1) {
#print "\e[2J\n";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
#printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
#printf "%7s %15s %5s %s %s\n", "SESSION", "MCAST Grp", "Port", "Open", "Last Data";
%JSONdata=();
# "Status" | "Reserve" | "Reserve" | "Reserve" | "Reserve" | "Spaltenanzahl" | "Zeilenanzahl" | "Beschriftung" | "Spalte1" | "Spalte2";
$JSONdata{'0'}="|||||||Session|Gruppe|Port|Open|Last";
my $jcount=1;
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
if ($mcdata{$_} eq "") {
#printf "%7d %15s %5s %4s %s\n", $session, $IP, $PORT, $open, 'NEVER';
$JSONdata{"$jcount"}="|||||||$session|$IP|$PORT|$open|NEVER";
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
#printf "%7d %15s %5s %4s more than %d sec ago\n", $session, $IP, $PORT, $open, $TimeOut;
$JSONdata{"$jcount"}="|||||||$session|$IP|$PORT|$open|>$TimeOut";
}
else {
#printf "%7d %15s %5s %4s %d seconds ago\n", $session, $IP, $PORT, $open,$atime-$mcasts{$_};
my $tdiff=$atime-$mcasts{$_};
$JSONdata{"$jcount"}="|||||||$session|$IP|$PORT|$open|>$tdiff";
}
}
$jcount++;
}
#printf "\nv1.4 by Andre Wisniewski\n";
sleep 1;
}
}
# Baut Sockets für Multicast Empfang auf und sichert die zuletzt empfangenen Daten und dazu einen Zeitstempel
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT) = split/:/,$IPPORT;
#print "Öffne $IP $PORT\n"; <STDIN>;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
$sock->recv($data,4096);
$mcdata{$IPPORT}="DATA received in the last $TimeOut seconds"; #$data;
$mcasts{$IPPORT}=time;
}
}
sub TCPServer {
#my %daten=%{$_[0]};
POE::Component::Server::TCP->new(
Alias => "SERVER",
Port => 11211,
ClientInput => sub {
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
print "Session ", $session->ID(), " got input: $input\n";
#$heap->{client}->put($input);
#my $rip0 = $heap->{remote_ip};
#my $rport = $heap->{remote_port};
#my $id = $session->ID();
#my $log = scalar localtime(time).": Send data to session $id, client: $rip0, clientport: $rport";
#$logbox->insert('end', $log);
#$logbox->see('end');
if ($input eq "GETDATA") {
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
my $senddata=$JSONObject->encode(\%JSONdata);
$heap->{client}->put($senddata);
}
}
);
}

View File

@@ -0,0 +1,155 @@
#!/bin/perl
use strict;
use Thread;
use IO::Socket::Multicast;
use POE;
use POE::Component::Server::TCP;
use JSON::XS;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my $TimeOut = 20;
my $starttime;
#fix
my %JSONdata :shared;
#TCPServer();
my $thr = new Thread (\&Main);
POE::Session->create(
inline_states => {
#loop => \&loop,
main => \&Main,
tcpserver => \&TCPServer,
_start => sub {
$_[KERNEL]->yield($_) for qw(main tcpserver);
}
}
);
POE::Kernel->run();
#StartMain();
#fix ende
sub Main {
# Konfigdatei einlesen
open CONF, "<config.txt";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
foreach (keys %mcasts) { my $thr = new Thread (\&WaitForMessage,$_); print "$_ gestartet\n";}
# Startzeit, lesbar
my $t=localtime;
# startzeit, als fortlaufende zahl
$starttime = time;
# Anzeige aufbauen
while (1) {
#print "\e[2J\n";
print ".\n";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
#printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
#printf "%7s %15s %5s %s %s\n", "SESSION", "MCAST Grp", "Port", "Open", "Last Data";
%JSONdata=();
# "Status" | "Reserve" | "Reserve" | "Reserve" | "Reserve" | "Spaltenanzahl" | "Zeilenanzahl" | "Beschriftung" | "Spalte1" | "Spalte2";
#$JSONdata{'0'}="|||||||Session|Gruppe|Port|Open|Last";
BuildJsonLine(0,undef,undef,undef,undef,undef,undef,undef,"SESSION","IP","PORT","OPEN","LAST UPDATE");
my $jcount=1;
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
my $line;
if ($mcdata{$_} eq "") {
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,"NEVER");
print "$line\n";
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,"> $TimeOut");
print "$line\n";
}
else {
my $tdiff=$atime-$mcasts{$_};
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,$tdiff);
print "$line\n";
}
}
$jcount++;
}
sleep 1;
}
}
sub WaitForMessage {
my ($IPPORT)=@_;
my ($SESSION, $IP, $PORT) = split/:/,$IPPORT;
#print "Öffne $IP $PORT\n"; <STDIN>;
my $sock;
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
sleep 1;
}
$sock->mcast_add($IP);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
$sock->recv($data,4096);
$mcasts{$IPPORT}=time;
}
}
sub TCPServer {
POE::Component::Server::TCP->new(
Alias => "SERVER",
Port => 11211,
ClientInput => sub {
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
print "Session ", $session->ID(), " got input: $input\n";
#$heap->{client}->put($input);
#my $rip0 = $heap->{remote_ip};
#my $rport = $heap->{remote_port};
#my $id = $session->ID();
#my $log = scalar localtime(time).": Send data to session $id, client: $rip0, clientport: $rport";
#$logbox->insert('end', $log);
#$logbox->see('end');
if ($input eq "GETDATA") {
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
my $senddata=$JSONObject->encode(\%JSONdata);
$heap->{client}->put($senddata);
}
}
);
}
sub BuildJsonLine {
my ($count,$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l)=@_;
my $line="$a|$b|$c|$d|$e|$f|$g|$h|$i|$j|$k|$l";
$JSONdata{"$count"}=$line;
return $line;
}
#fix {
sub StartMain {
}
#} fix

View File

@@ -0,0 +1,33 @@
#!C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp-gui.exe
PAP-Version: 1.0
Packer: C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp.exe
Script: mcastrcv3.pl
Cwd: G:\My Documents\Diverse Skripts\JSON Server Client\MCast Receiver
Clean: 0
Date: 2011-03-17 15:59:07
Debug:
Dependent: 0
Dyndll: 0
Exe: mcastrcv3.exe
Force: 0
Gui: 0
Hostname: neticfsys03
Manifest:
No-Compress: 0
No-Logo: 0
Runlib:
Shared: none
Tmpdir:
Verbose: 0
Version-Comments:
Version-CompanyName: ICF Systems AG
Version-FileDescription:
Version-FileVersion: 3.1
Version-InternalName: Multicast Receiver
Version-LegalCopyright: Andre Wisniewski
Version-LegalTrademarks:
Version-OriginalFilename: mcastrcv3.exe
Version-ProductName: Multicast Receiver
Version-ProductVersion: 3.1
Warnings: 0
Xclude: 0

View File

@@ -0,0 +1,33 @@
#!C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp-gui.exe
PAP-Version: 1.0
Packer: C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp.exe
Script: mcastrcv_sequences.pl
Cwd: I:\Skripte\JSON Server Client\MCast Receiver
Clean: 0
Date: 2011-05-31 14:19:24
Debug:
Dependent: 0
Dyndll: 0
Exe: mcastrcv_sequences.exe
Force: 0
Gui: 0
Hostname: neticfsys03
Manifest:
No-Compress: 0
No-Logo: 0
Runlib:
Shared: none
Tmpdir:
Verbose: 0
Version-Comments:
Version-CompanyName: ICF Systems AG
Version-FileDescription:
Version-FileVersion: 3.1
Version-InternalName: Multicast Receiver
Version-LegalCopyright: Andre Wisniewski
Version-LegalTrademarks:
Version-OriginalFilename: mcastrcv3.exe
Version-ProductName: Multicast Receiver
Version-ProductVersion: 3.1
Warnings: 0
Xclude: 0

View File

@@ -0,0 +1,208 @@
#!/bin/perl
use strict "vars";
#use strict "refs";
use strict "subs";
use threads;
#use threads::shared;
use Time::HiRes qw /usleep/;
use IO::Socket::Multicast;
my @a10; my @a11; my @a12; my @a13; my @a14; my @a15; my @a16; my @a17; my @a18; my @a19;
my @a20; my @a21; my @a22; my @a23; my @a24; my @a25; my @a26; my @a27; my @a28; my @a29;
my @a30; my @a31; my @a32; my @a33; my @a34; my @a35; my @a36; my @a37; my @a38; my @a39;
@a10=("hallo","blöder","text");
my @arrays = qw /a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39/;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my $TimeOut = 20;
my $starttime;
my %LASTV :shared;
my %MISS :shared;
# Konfigdatei einlesen
open CONF, "<config.txt";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
my $i=0;
my @aref;
my $thr2 = threads->new(\&Write_Gaps);
foreach (keys %mcasts) {
my $arr=$arrays[$i];
$aref[$i]=\@$arr;
my $thr1 = threads->new(\&WaitForMessage,$_,$aref[$i]);
$i++;
}
# Startzeit, lesbar
my $t=localtime;
$starttime = time;
while (1) {
sleep 1;
}
sub WaitForMessage {
my ($IPPORT,$ARR)=@_;
my ($SESSION, $IP, $PORT) = split/:/,$IPPORT;
#print "Öffne $IP $PORT\n"; <STDIN>;
my $sock;
my @ta=@{$ARR};
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
Time::HiRes::sleep(0.1);
}
$sock->mcast_add($IP);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
#print ".\n";
$sock->recv($data,4096);
#print "$data\n";
my @a=split//,$data;
my $b=$a[10];
my $c=$a[11];
$b=unpack("Cn",$b);
$c=unpack("Cn",$c);
my $d=($b<<16)+$c;
###print "$IPPORT $d\n";
if (MissedValue($d,$IPPORT)) {
DelFromMissing($d,$IPPORT);
}
else {
if (ExistPrevSeqNr($d,$IPPORT)) {
if (LastSeqNrGreaterThanLast($d,$IPPORT)) {
if (MissingSeqNumbers($d,$IPPORT)) {
my @missed=MissedSeqNumbers($d,$IPPORT);
PushMissedSeqNr($IPPORT,@missed);
}
else {
RemLastSeqNr($d,$IPPORT);
}
}
}
else {
RemLastSeqNr($d,$IPPORT);
}
}
#sleep 1;
}
}
sub MissedValue {
my ($d,$s)=@_;
#print "MV\n";
foreach (@{$MISS{$s}}) {
if ( $_ == $d ) {
return 1;
}
}
return 0;
}
sub ExistPrevSeqNr {
my ($d,$s)=@_;
#print "EPSN\n";
if ( $LASTV{$s} >= 0 ) {
return 1;
}
return 0;
}
sub LastSeqNrGreaterThanLast {
my ($d,$s)=@_;
#print "LSNGTL\n";
if ( $d > $LASTV{$s} ) {
return 1;
}
return 0;
}
sub MissingSeqNumbers {
my ($d,$s)=@_;
#print "MSQ\n";
if ( $d > $LASTV{$s}+1 ) {
return 1;
}
return 0;
}
sub MissedSeqNumbers {
my ($d,$s)=@_;
#print "MDSQ\n";
my @missing;
print "H\n";
if ($LASTV{$s} > 0) {
foreach ($i=$LASTV{$s};$i<$d;$i++) {
push @missing, $i;
#print "$i\n";
}
}
print "MA- @missing -MA\n";
return @missing;
}
sub PushMissedSeqNr {
my ($s,@d)=@_;
#print "PSQ\n";
push @{$MISS{$s}}, @d;
}
sub RemLastSeqNr {
my ($d,$s)=@_;
#print "RMSN\n";
$LASTV{$s} = $d;
}
sub DelFromMissing {
my ($d,$s)=@_;
#print "DFM\n";
my $i=0;
foreach (@{$MISS{$s}}) {
if ($d == $_) {
delete $MISS{$s}[$i];
}
$i++;
}
}
sub Write_Gaps {
while (1) {
#print "GAPS 1\n";
foreach (keys %MISS) {
print "$_\n";
foreach (@{$MISS{$_}}) {
print "$_ ";
}
print "\n\n";
}
sleep (5);
#print "GAPS 2\n";
}
}

View File

@@ -0,0 +1,33 @@
#!C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp-gui.exe
PAP-Version: 1.0
Packer: C:\Program Files\ActiveState Perl Dev Kit 8.2.1\bin\perlapp.exe
Script: mcastrcv_universal.pl
Cwd: I:\Skripte\JSON Server Client\MCast Receiver
Clean: 1
Date: 2011-05-31 14:18:23
Debug:
Dependent: 0
Dyndll: 0
Exe: mcastrcv_universal.exe
Force: 0
Gui: 0
Hostname: neticfsys03
Manifest:
No-Compress: 0
No-Logo: 0
Runlib:
Shared: none
Tmpdir:
Verbose: 0
Version-Comments:
Version-CompanyName: ICF Systems AG
Version-FileDescription:
Version-FileVersion: 3.1
Version-InternalName: Multicast Receiver
Version-LegalCopyright: Andre Wisniewski
Version-LegalTrademarks:
Version-OriginalFilename: mcastrcv3.exe
Version-ProductName: Multicast Receiver
Version-ProductVersion: 3.1
Warnings: 0
Xclude: 0

View File

@@ -0,0 +1,223 @@
#!/bin/perl
use strict "vars";
#use strict "refs";
use strict "subs";
use Thread;
#use threads::shared;
use Time::HiRes qw /usleep/;
use IO::Socket::Multicast;
use POE;
use POE::Loop::Select;
use POE::Resource::Aliases;
use POE::Resource::Events;
use POE::Resource::Extrefs;
use POE::Resource::FileHandles;
use POE::Resource::SIDs;
use POE::Resource::Sessions;
use POE::Resource::Signals;
#use POE::Resource::Statistics;
my @a10; my @a11; my @a12; my @a13; my @a14; my @a15; my @a16; my @a17; my @a18; my @a19;
my @a20; my @a21; my @a22; my @a23; my @a24; my @a25; my @a26; my @a27; my @a28; my @a29;
my @a30; my @a31; my @a32; my @a33; my @a34; my @a35; my @a36; my @a37; my @a38; my @a39;
my @arrays = qw /a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28 a29 a30 a31 a32 a33 a34 a35 a36 a37 a38 a39/;
use POE::Component::Server::TCP;
use JSON::XS;
my %mcasts :shared;
my %mcdata :shared;
my %mcopen :shared;
my $TimeOut = 20;
my $starttime;
my %JSONdata :shared;
my $TCPSERVERIP;
my $TCPSERVERPORT;
if ($ARGV[0] eq "") {
$TCPSERVERIP="0.0.0.0"; $TCPSERVERPORT="11211";
}
else {
if ($ARGV[1] eq "") { wrong_start("Kein Port"); }
my $e=$ARGV[1];
if ($e<1024 or $e>65535) {wrong_start("Ungültiger Port");}
$TCPSERVERPORT = $e;
my ($a,$b,$c,$d) = split/\./,$ARGV[0];
if ($ARGV[0] eq "0.0.0.0") {
$TCPSERVERIP=0.0.0.0;
}
else {
if ($a<1 or $a>255 or $b<0 or $b>255 or $c<0 or $c>255 or $d<1 or $d>255) { wrong_start("Ungültige IP"); }
$TCPSERVERIP = $a . "." . $b . "." . $c . "." . "$d";
}
}
my $thr = new Thread(\&Main);
# Konfigdatei einlesen
open CONF, "<config.txt";
my @config=<CONF>;
close CONF;
foreach (@config) {
chomp;
next if ($_ =~ /^#/);
next if (length($_)==0);
$mcasts{$_}='';
}
# Threads für die einzelnen Multicastgruppen anstarten
#share(@seq2);
my $i=0;
my @aref;
foreach (keys %mcasts) {
my $arr=$arrays[$i];
$aref[$i]=\@$arr;
my $thr1 = new Thread(\&WaitForMessage,$_,$aref[$i]);
# my $thr2 = new Thread(\&Write_Gaps,$i,$aref[$i]);
$i++;
}
# Startzeit, lesbar
my $t=localtime;
$starttime = time;
POE::Component::Server::TCP->new(
Alias => "SERVER",
Port => $TCPSERVERPORT,
Address => $TCPSERVERIP,
ClientInput => sub {
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
print "Session ", $session->ID(), " got input: $input\n";
CheckInput($session, $heap, $input);
}
);
POE::Kernel->run();
sub Main {
# Anzeige aufbauen
while (1) {
#print "\e[2J\n";
#aktuelle zeit, als fortlaufende zahl
my $atime=time;
#printf "program runs since %s (for %d seconds)\n\n", $t, $atime-$starttime;
#printf "%7s %15s %5s %s %s\n", "SESSION", "MCAST Grp", "Port", "Open", "Last Data";
%JSONdata=();
# "Status" | "Reserve" | "Reserve" | "Reserve" | "Reserve" | "Spaltenanzahl" | "Zeilenanzahl" | "Beschriftung" | "Spalte1" | "Spalte2";
#$JSONdata{'0'}="|||||||Session|Gruppe|Port|Open|Last";
# sp. zeil
BuildJsonLine(0,undef,undef,undef,undef,$atime,undef,undef,"SESSION","IP","PORT","OPEN","LAST UPDATE");
my $jcount=1;
foreach (sort keys %mcasts) {
my ($session,$IP,$PORT)=split /:/,$_;
my $open="no";
$open="yes" if ($mcopen{$_} == 1);
my $line;
my $jcountt="text".$jcount;
if ($mcdata{$_} eq "") {
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,"NEVER");
#print "$line\n";
}
else {
if ($atime-$mcasts{$_} > $TimeOut) {
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,"> $TimeOut");
#print "$line\n";
}
else {
my $tdiff=$atime-$mcasts{$_};
$line = BuildJsonLine($jcount,undef,undef,undef,undef,undef,undef,undef,$session,$IP,$PORT,$open,$tdiff);
#print "$line\n";
}
}
$jcount++;
}
sleep 1;
}
}
sub WaitForMessage {
my ($IPPORT,$ARR)=@_;
my ($SESSION, $IP, $PORT) = split/:/,$IPPORT;
#print "Öffne $IP $PORT\n"; <STDIN>;
my $sock;
my @ta=@{$ARR};
$mcopen{$IPPORT}=0;
while (!$sock) {
$sock = IO::Socket::Multicast->new(LocalPort=>$PORT,ReuseAddr=>1);
Time::HiRes::sleep(0.1);
}
$sock->mcast_add($IP);
$mcopen{$IPPORT}=1;
my $data;
while (1) {
$sock->recv($data,4096);
#print "$data\n";
# my @a=split//,$data;
# my $b=$a[10];
# my $c=$a[11];
# $b=unpack("Cn",$b);
# $c=unpack("Cn",$c);
# my $d=($b<<16)+$c;
# push(@ta,$d);
# print "\nRCV SEQ on $IPPORT\n$d\n@ta\n";
$mcasts{$IPPORT}=time;
$mcdata{$IPPORT}=time;
###
sleep 1;
}
}
sub BuildJsonLine {
my ($count,$a,$b,$c,$d,$e,$f,$g,$h,$i,$j,$k,$l)=@_;
my $line="$a|$b|$c|$d|$e|$f|$g|$h|$i|$j|$k|$l";
#print "$count\n";
$JSONdata{$count}=$line;
return $line;
}
sub CheckInput {
my ($session, $heap,$input)=@_;
if ($input eq "GETDATA") {
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
my $senddata=$JSONObject->encode(\%JSONdata);
$heap->{client}->put($senddata);
}
}
sub wrong_start {
print "\n\n\t$_[0]\n\nAufruf:\n\nmcastrcv3 [<IP> <PORT>]\n\nOhne Angabe von IP und Port wird auf 0.0.0.0 11211 gehört\n\n";
exit;
}
sub Write_Gaps {
my ($a,$aref)=@_;
my @ta=@{$aref};
while (1) {
open FH, ">$a.txt";
#print "@arr\n";
foreach (@ta) {
print FH "$_\n";
print "\nWR SEQ\n$_\n";
}
close FH;
sleep (30);
}
}

View File

@@ -0,0 +1,126 @@
# comments (#) are allowed
# complete empty line are allowed (no spaces)
# MC_ADDR:PORT
#Service ID 1
#Liffe 1:224.0.64.2:50001
#Liffe 1:224.0.65.2:50005
#Service ID 2
Liffe 2:224.0.64.3:50001
Liffe 2:224.0.65.3:50005
#Service ID 4
#Liffe 4:224.0.64.5:50001
#Liffe 4:224.0.65.5:50005
#Service ID 6
#Liffe 6:224.0.64.7:50001
#Liffe 6:224.0.65.7:50005
#Service ID 36
#Liffe 36:224.0.64.8:50001
#Liffe 36:224.0.65.8:50005
#Service ID 101
#Liffe 101:224.0.64.2:50002
#Liffe 101:224.0.65.2:50006
#Service ID 102
#Liffe 102:224.0.64.3:50002
#Liffe 102:224.0.65.3:50006
#Service ID 104
#Liffe 104:224.0.64.5:50002
#Liffe 104:224.0.65.5:50006
#Service ID 106
#Liffe 106:224.0.64.7:50002
#Liffe 106:224.0.65.7:50006
#Service ID 136
#Liffe 136:224.0.64.8:50002
#Liffe 136:224.0.65.8:50006
#Service ID 51
#Liffe 51:224.0.64.2:50003
#Liffe 51:224.0.65.2:50007
#Service ID 52
#Liffe 52:224.0.64.3:50003
#Liffe 52:224.0.65.3:50007
#Service ID 54
#Liffe 54:224.0.64.5:50003
#Liffe 54:224.0.65.5:50007
#Service ID 56a
#Liffe 56a:224.0.64.7:50003
#Liffe 56a:224.0.65.7:50007
#Service ID 56b
#Liffe 56b:224.0.64.8:50003
#Liffe 56b:224.0.65.8:50007
#Service ID 151
#Liffe 151:224.0.64.2:50004
#Liffe 151:224.0.65.2:50008
#Service ID 152
#Liffe 152:224.0.64.3:50004
#Liffe 152:224.0.65.3:50008
#Service ID 154
#Liffe 154:224.0.64.5:50004
#Liffe 154:224.0.65.5:50008
#Service ID 156a
#Liffe 156a:224.0.64.7:50004
#Liffe 156a:224.0.65.7:50008
#Service ID 156b
#Liffe 156b:224.0.64.8:50004
#Liffe 156b:224.0.65.8:50008
# Cash
#
#Cash 901:224.0.52.4:21028
#Cash 901:224.0.53.4:21029
#Cash 902:224.0.52.5:21030
#Cash 902:224.0.53.5:21031
#Cash 903:224.0.52.6:21032
#Cash 903:224.0.53.6:21033
#Cash 904:224.0.52.7:21034
#Cash 904:224.0.53.7:21035
#Cash 905:224.0.52.8:21036
#Cash 905:224.0.53.8:21037
#Cash 906:224.0.52.9:21038
#Cash 906:224.0.53.9:21039
#Cash 907:224.0.52.10:21040
#Cash 907:224.0.53.10:21041
#Cash 908:224.0.52.11:21042
#Cash 908:224.0.53.11:21043
#Cash 909:224.0.52.12:21044
#Cash 909:224.0.53.12:21045
#Cash 910:224.0.52.13:21046
#Cash 910:224.0.53.13:21047
#Cash 911:224.0.52.14:21048
#Cash 911:224.0.53.14:21049
#Cash 912:224.0.52.15:21050
#Cash 912:224.0.53.15:21051
#Cash 913:224.0.52.16:21052
#Cash 913:224.0.53.16:21053
#Cash 914:224.0.52.21:21062
#Cash 914:224.0.53.21:21063

View File

@@ -0,0 +1,55 @@
#!/bin/perl
use POE;
use POE::Component::Server::TCP;
use JSON::XS;
use strict;
my %data;
$data{"0"}="hallo0";
$data{"1"}="hallo1";
TCPServer (\%data);
POE::Kernel->run();
sub TCPServer {
my %daten=%{$_[0]};
POE::Component::Server::TCP->new(
Alias => "SERVER",
Port => 11211,
ClientInput => sub {
my ($session, $heap, $input) = @_[SESSION, HEAP, ARG0];
#print "Session ", $session->ID(), " got input: $input\n";
#$heap->{client}->put($input);
#my $rip0 = $heap->{remote_ip};
#my $rport = $heap->{remote_port};
#my $id = $session->ID();
#my $log = scalar localtime(time).": Send data to session $id, client: $rip0, clientport: $rport";
#$logbox->insert('end', $log);
#$logbox->see('end');
if ($input eq "GETDATA") {
my $JSONObject = JSON::XS->new->ascii->pretty->allow_nonref();
my $senddata=$JSONObject->encode(\%daten);
$heap->{client}->put($senddata);
}
}
);
}
# %hash;
#
# Tabellenheader
# ID: Zeilennummer 0 beschreibt Header
#
# $hash{0}="Status" | "Reserve" | "Reserve" | "Reserve" | "Reserve" | "Spaltenanzahl" | "Zeilenanzahl" | "Beschriftung" | "Spalte1" | "Spalte2"
#
# Status 0-7; 0 critical (RED); 4 warning (ORANGE); 7 good (GREEN)
#