fin;
fin;
cs.OnRead (Expéditeur : TObject ; Socket : TCustomWinSocket) ;
var
sTemp:chaîne;
bufSend: pointeur;
commencer
sRecv:=Socket.ReceiveText;
Cas sRecv[1] de
MP_REFUSE:ShowMessage('Évanouissement, être refusé !');
MP_ACCEPT : début
fsSend:=TFileStream.Create(OpenDialog1.FileName,fmOpen);
//iBYTEPERSEND est une constante, la taille du paquet envoyé à chaque fois.
Socket.SendText(MP_FILEPROPERTY+Trunc(fsSend.Size/iBYTEPERSEND)+1);
fin;
MP_NEXTWILLBEDATA : début
Socket.SendText(MP_NEXTWILLBEDATA);
fin;
MP_DATA : début
essayer
GetMem(bufSend,iBYTEPERSEND+1);
si (fsSend.Position+1+iBYTEPERSEND) < fsSend.Size alors
commencer
fsSend.Read(bufSend^,iBYTEPERSEND);
Socket.SendBuf(bufSend^,iBYTEPERSEND);
fsSend.Free;
fin//Envoi ordinaire, la taille est iBYTEPERSEND
sinon commencer
fsSend.Read(bufSend^,fsSend.Size-fsSend.Position-1);
Socket.SendBuf(bufSend^,fsSend.Size-fsSend.Position-1);
fin;//La dernière fois à envoyer, envoyer les données restantes
enfin
FreeMem(bufSend,iBYTEPERSEND+1);
fin ;{d'essayer}
fin;
MP_ABORT : début
//Annulé :(
fsSend.Free;
fin;
fin ;{du cas}
fin;
Procédure d'organisation :
Ajoutez un jugement d'erreur, optimisez le programme, combinez le serveur et le client, ajoutez l'affichage de la progression du temps restant, permettez de transférer plusieurs fichiers en même temps et ajoutez une fonction de discussion, et cela devient un bon transfert de fichiers point à point. programme.