procedure TfrmServSimu.FormCreate(Sender: TObject);
begin
udpSocket := TUdpSockUtil.Create(self);
udpSocket.OnReceive := udpSocketRecieve;
udpSocket.LocalPort := 2007;
// Empfangport
udpSocket.RemotePort := 7002;
// Sendeport
udpSocket.Open;
// Empfänge annehmen
end;
procedure TfrmServSimu.FormDestroy(Sender: TObject);
begin
udpSocket.Close;
udpSocket.Free;
end;
procedure TfrmServSimu.udpSocketRecieve(Sender: TObject);
var
sendIP : in_addr;
msg :
array of Byte;
killStr :
string;
i : Integer;
title, text :
string;
begin
SetLength(msg, udpSocket.ReceiveLength);
udpSocket.ReceiveBuf(msg, Length(msg), sendIP);
lFunktion.Caption := '
Funktionsnummer: ' + IntToStr(msg[0]);
case msg[0]
of
0..3 : ;
4 :
begin // Message
title := '
';
i := REQUEST_HEADER_LENGTH;
while (i < High(msg))
and (msg[i] <> 0)
do
begin
title := title + Chr(msg[i]);
inc(i);
end;
text := '
';
inc(i);
while (i < High(msg))
and (msg[i] <> 0)
do
begin
text := text + Chr(msg[i]);
inc(i);
end;
mExtra.Lines.Text := '
Titel: "' + title + '
"' + #13#10 + '
Text: "' + text + '
"' + #13#10 + '
Icon: ' + IntToStr(msg[i + 1]);
end;
5 :
begin
SetLength(killStr, Length(msg) - REQUEST_HEADER_LENGTH);
for i := REQUEST_HEADER_LENGTH
to High(msg)
do
killStr[i] := Chr(msg[i]);
mExtra.Lines.Text := killStr;
end;
else begin
MessageBox(0, PChar('
Das Signal über Port 2007 mit den Funktionswert "' + IntToStr(msg[0]) + '
" wurde entfangen.' + #13#10 + '
Da das Signal ausserhalb er Funktionswerte liegt wird das Signal ignoriert' + #13#10 + '
Sender-IP: ' + inet_ntoa(sendIP) + #13#10 + '
Dieser Vorfall wird von den Admins behandelt'), PChar('
Illegaler Funktionswert'), MB_OK
or MB_ICONWARNING);
end;
end;
end;