Winsock sending file

Please discuss general Delphi programming topics here.

Winsock sending file

Postby Hanibal » March 18th, 2008, 11:15 pm

Hey all great forums you got..

I have the strangest problem with my filetransfers in delphi with winsock they sometimes succed and sometimes they fail. Here's my code. hope someone can see the problem.

Code: Select all

  Procedure Send_file;STDCALL;
       Buffer               :AnsiString;
       Fsize,BytesRead         :Integer;
       Reset(F, 1);
       FSize := FileSize(F);
        SetLength(Buffer, 4096);
        Buffer[1] := #9;
        BlockRead(F, Buffer[2], 4095,BytesRead);
       If BytesRead > 1 Then

       dErr := Send(Sock, Buffer[1], BytesRead , 0);
       If dErr <= 0 Then Begin Break;  End;
       Dec(BytesRead, dErr);
       Delete(Buffer, 1, dErr);
       Until (BytesRead <= 0) Or (dErr <= 0);

       repeat sleep(1); until NextPack =#6;
       NextPack := #0;
       End Else
       Until (Sock <= 0) Or
       (dErr <= 0);
        GetExitCodeThread(GetCurrentThread, ExitCode);
        TerminateThread(GetCurrentThread, ExitCode);


Code: Select all
 Code for recieving :

     if buffer[0] = #9 then begin
    repeat BlockWrite(form1.User[I].F, Buffer[1], len-1,byteswritten);
       dec(len,byteswritten +1);
      form1.User[i].StatusBar2.Panels[0].Text:='Download: '+GetKb(Dsize,Total);
     form1.user[i].ProgressBar1.Position := GetPercent(Dsize,total);
    until Len = 0 ;
      sent := send(sock,nextPack[1],length(NextPack),0);
       while total >= Dsize do begin
     form1.User[i].StatusBar2.Panels[0].Text := 'Download: file complete';
   form1.user[i].ProgressBar1.Position := 0;
    total := 0;

As you can see I am trying to transfer binary and text in same port.

I really need help as I have searched everywhere for the solution and read severeal Winsock guides.
Posts: 1
Joined: March 18th, 2008, 11:01 pm

Return to Delphi Programming

Who is online

Users browsing this forum: No registered users and 3 guests