procedure TFMain.srvAccept(Sender: TObject; ClientSocket: TCustomIpClient);
var
_trans: trans;
rec, rec2: integer;
sync: TSyncThread;
Image: TImage;
_Label: TLabel;
i: integer;
Comp: TComponent;
bild: TMemoryStream;
ini: TIniFile;
VNCTemp:
String;
Err: Integer;
buff:
array[0..2048]
of byte;
jpg: TJpegImage;
//Bei starten des Thread ist WaitForData False
WaitForData: integer;
begin
Logger('
Verbindung wurde akzeptiert: ' + ClientSocket.RemoteHost);
Image:=
nil;
_Label:=
nil;
bild:= TMemoryStream.Create();
try
ini:= TIniFile.Create(INIFile);
VNCTemp:= ini.ReadString('
VNC', '
Template', '
');
CopyFile(PChar(VNCTemp + '
\config.vnc'), PChar(VNCTemp + '
\' + clientSocket.RemoteHost + '
.vnc'), false);
ini.Free();
ini:= TIniFile.Create(VNCTemp + '
\'+ clientSocket.RemoteHost + '
.vnc');
ini.WriteString('
connection', '
host', clientSocket.RemoteHost);
ini.Free();
except
on E:
Exception do
begin
Logger('
srvAccept: config.vnc konnnte nicht kopiert werden. Fehler: ' + E.
Message);
end;
end;
while clientSocket.Connect = true
do
begin
fillchar(_trans, sizeof(_trans), 0);
rec:= 0;
while rec <> sizeof(_trans)
do
begin
//CHG-002
if ClientSocket.WaitForData(15000) = false
then
begin
logger('
WaitForData is false');
ClientSocket.Close;
end;
sleep(10);
rec2:= ClientSocket.PeekBuf(buff[rec], sizeof(_trans)-rec);
//--CHG-002 ende
if rec2 = 0
then
begin
ClientSocket.Close;
break;
end;
if rec2 <> sizeof(_trans)
then
begin
logger('
Windows MSG: ' + SysErrorMessage(GetLastError));
logger('
srvAccept: TCP/IP Grösse der Pakete stimmt nicht: ' + ClientSocket.RemoteHost);
logger('
Empfangen: ' + inttostr(rec2));
logger('
Erwartet : ' + inttostr(sizeof(_trans)));
fillchar(_trans, 0, sizeof(_trans));
sleep(100);
//CHG-003
logger('
Versuches es nochmals ...');
rec2:= ClientSocket.ReceiveBuf(buff[rec], sizeof(_trans)-rec);
if rec2 <> sizeof(_trans)
then
begin
logger('
Wieder keine Daten ... schiessen der Verbindung');
ClientSocket.Close;
break;
end;
logger('
Die Daten wurde vollständig empfangen');
//CHG-003 Ende
end
else
begin
//CHG-002
rec2:= ClientSocket.ReceiveBuf(buff[rec], sizeof(_trans)-rec);
end;
rec:= rec + rec2;
end;
move(buff, _trans, sizeof(_trans));
if _trans.product <> PRODUCT
then
begin
Sync:= TSyncThread.Create(true);
logger('
srvAccept: Falsche Paketart PRODUCT, Verbindung beendet: ' + ClientSocket.RemoteHost);
clientSocket.Disconnect;
sync.setPicture(Image,
nil);
Sync.Suspended:= false;
exit;
end;
if _trans.seg = 0
then
begin
Bild.Position:= 0 ;
Bild.Clear;
end;
Bild.
Write(_trans.data, _trans.size);
if _trans.seg = _trans.maxseg
then
begin
//logger('Paket wurde komplett empfangen');
bild.Position:= 0;
for i:= 0
to MAXIPHASH
do
begin
if IPHash[i].DesktopID = StrtoInt(_trans.whois)
then
begin
IPHash[i].IPAddr:= ClientSocket.RemoteHost;
end;
end;
if Image =
NIL then begin
for i:= 0
to FMain.ComponentCount -1
do
begin
Comp:= FMain.Components[i];
if Comp
is TImage
then
begin
if Comp.Tag = StrtoInt(_trans.whois)
then
Image:= (comp
as TImage)
end;
if comp
is TLabel
then
begin
if comp.tag = strtoint(_trans.whois)
then
_label:= (comp
as TLabel);
end;
end;
end;
if Image <>
NIL then
begin
try
Sync:= TSyncThread.Create(true);
//02.05.2010 CHG-002
Sync.FreeOnTerminate:= true;
//CHG-002 Ende
sync.setPicture(Image, bild);
Sync.Suspended:= false;
if _trans.user <> '
'
then
_Label.Caption:= _trans.user;
//logger('Bild Sync ende.');
except
on e:
Exception do
begin
Logger('
Sync.SetPicture: ' + e.
Message);
end;
end;
end;
end;
end;
// End connected
Sync:= TSyncThread.Create(true);
sync.setPicture(Image,
nil);
Sync.Suspended:= false;
_Label.Caption:= '
';
Logger('
srvAccept: Thread mit der IP: ' + clientSocket.RemoteHost + '
wurde geschlossen');
end;
// End Function