fim;
fim;
cs.OnRead(Remetente: TObject;Socket: TCustomWinSocket);
var
temperatura:string;
bufSend:ponteiro;
começar
sRecv:=Socket.ReceiveText;
Caso sRecv[1] de
MP_REFUSE:ShowMessage('Fraco,seja recusado!');
MP_ACCEPT:início
fsSend:=TFileStream.Create(OpenDialog1.FileName,fmOpen);
//iBYTEPERSEND é uma constante, o tamanho do pacote enviado a cada vez.
Socket.SendText(MP_FILEPROPERTY+Trunc(fsSend.Size/iBYTEPERSEND)+1);
fim;
MP_NEXTWILLBEDATA:início
Socket.SendText(MP_NEXTWILLBEDATA);
fim;
MP_DATA:início
tentar
GetMem(bufSend,iBYTEPERSEND+1);
if (fsSend.Position+1+iBYTEPERSEND) <fsSend.Size então
começar
fsSend.Read(bufSend^,iBYTEPERSEND);
Socket.SendBuf(bufSend^,iBYTEPERSEND);
fsSend.Free;
end // Envio normal, o tamanho é iBYTEPERSEND
senão começar
fsSend.Read(bufSend^,fsSend.Size-fsSend.Position-1);
Socket.SendBuf(bufSend^,fsSend.Size-fsSend.Position-1);
end; //A última vez que enviar, envia os dados restantes
finalmente
FreeMem(bufSend,iBYTEPERSEND+1);
fim;{de tentativa}
fim;
MP_ABORT:início
//Cancelado :(
fsSend.Free;
fim;
fim;{do caso}
fim;
Procedimento de organização:
Adicione julgamento de erro, otimize o programa, combine o servidor e o cliente, adicione a exibição do progresso do tempo restante, possibilite a transferência de vários arquivos ao mesmo tempo e adicione uma função de bate-papo, e torna-se uma boa transferência de arquivos ponto a ponto programa.