fin;
fin;
cs.OnRead(Remitente: TObject;Socket: TCustomWinSocket);
var
sTemp:cadena;
buffEnviar:puntero;
comenzar
sRecv:=Socket.ReceiveText;
Caso sRecv[1] de
MP_REFUSE:ShowMessage('¡Desmayo, ser rechazado!');
MP_ACCEPT:comenzar
fsSend:=TFileStream.Create(OpenDialog1.FileName,fmOpen);
//iBYTEPERSEND es una constante, el tamaño del paquete enviado cada vez.
Socket.SendText(MP_FILEPROPERTY+Trunc(fsSend.Size/iBYTEPERSEND)+1);
fin;
MP_NEXTWILLBEDATA:comenzar
Socket.SendText(MP_NEXTWILLBEDATA);
fin;
MP_DATA:comenzar
intentar
GetMem(bufSend,iBYTEPERSEND+1);
si (fsSend.Position+1+iBYTEPERSEND) < fsSend.Size entonces
comenzar
fsSend.Read(bufSend^,iBYTEPERSEND);
Socket.SendBuf(bufSend^,iBYTEPERSEND);
fsSend.Gratis;
fin//Envío normal, el tamaño es iBYTEPERSEND
si no, empezar
fsSend.Read(bufSend^,fsSend.Size-fsSend.Position-1);
Socket.SendBuf(bufSend^,fsSend.Size-fsSend.Position-1);
end;// La última vez que se envía, envía los datos restantes
finalmente
FreeMem(bufSend,iBYTEPERSEND+1);
fin; {de intentar}
fin;
MP_ABORT:comenzar
//Cancelado :(
fsSend.Gratis;
fin;
fin; {de caso}
fin;
Procedimiento de organización:
Agregue juicio de errores, optimice el programa, combine el Servidor y el Cliente, agregue la visualización del progreso del tiempo restante, haga posible transferir varios archivos a la vez y agregue una función de chat, y se convierte en una buena transferencia de archivos punto a punto. programa.