procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var EmpfTxt :
string;
nReceived : Longint;
datei : TFileStream;
begin
EmpfTxt := Socket.ReceiveText;
if (copy(EmpfTxt,1,4) = '
Text')
then begin
delete(EmpfTxt,1,4);
EChatWindow.SelAttributes.Color := clblue;
EChatWindow.Lines.Add(EmpfTxt);
end ELSE if (copy(EmpfTxt,1,9) = '
Dateiname')
then begin
delete(EmpfTxt,1,9);
Dateiname := EmpfTxt;
end ELSE begin
case CliStatus
of
csIdle:
begin
Socket.ReceiveBuf(Buffer, sizeof(Buffer));
if (copy(Buffer,1,5) = '
Datei')
then CliStatus := csFile;
Buffer := '
';
end;
//ankommende Datei
csFile:
begin
if not Working
then
begin
working := true;
datei := TFileStream.Create(ExtractFilePath(ParamStr(0) + 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;
end;
//Und zum Senden
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('
Dateiname' + 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('
Dateiname' + 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;