procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var EmpfTxt :
string;
nReceived : Longint;
datei : TFileStream;
begin
case CliStatus
of
csIdle:
begin
Socket.ReceiveBuf(Buffer, sizeof(Buffer));
if (copy(Buffer,1,5) = '
Datei')
then CliStatus := csFile;
if (copy(Buffer,1,4) = '
Text')
then begin
EmpfTxt := Buffer;
delete(EmpfTxt,1,4);
EChatWindow.SelAttributes.Color := clblue;
EChatWindow.Lines.Add(EmpfTxt);
end;
if (copy(Buffer,1,5) = '
DName')
then begin
EmpfTxt := Buffer;
delete(EmpfTxt,1,5);
Dateiname := EmpfTxt;
end;
Buffer := '
';
end;
//ankommende Datei
csFile:
begin
if not Working
then
begin
working := true;
datei := TFileStream.Create(ExtractFilePath(Application.ExeName)+'
\'+dateiname, fmCreate);
try
while True
do
begin
nReceived := Socket.ReceiveBuf(Buffer, sizeof(Buffer));
if nReceived <= 0
then Break
else Datei.WriteBuffer(Buffer, nReceived);
Sleep(200);
end;
Datei.position := 0;
finally
Datei.Free;
end;
CliStatus := csIdle;
working := false;
end;
end;
end;
end;
procedure TForm1.btnsendfilesClick(Sender: TObject);
var i, k : Longint;
begin
for i := 0
to ListBox1.Items.Count-1
do
begin
dateiname := ListBox1.Items[i];
k := length(dateiname);
while (dateiname[k] <> '
\')
do dec(k);
//Dateiname rausfinden
dateiname := copy(dateiname,k+1,length(dateiname)-k);
try
if server
then begin
ServerSocket1.Socket.Connections[0].SendText('
DName' + Dateiname);
//dateiname senden
ServerSocket1.Socket.Connections[0].SendText('
Datei');
ServerSocket1.Socket.Connections[0].SendStream(TFileStream.Create(Listbox1.Items[i], fmOpenRead
or fmShareDenyWrite));
end
else begin
ClientSocket1.Socket.SendText('
DName' + Dateiname);
ClientSocket1.Socket.SendText('
Datei');
//sagen dass jetzt ne Datei kommt
ClientSocket1.Socket.SendStream(TFileStream.Create(Listbox1.Items[i], fmOpenRead
or fmShareDenyWrite));
end;
finally
// NICHTS
end;
end;
end;