Q&A

  • 소켓데이타 파일처리
밑에 처럼 했는데 서버에서 보낸 파일이 깨져 버리네요..
이 처리를 어떻게 해야할지 모르겠습니다..
제가 여기서 jpg파일로 전환할때 뭐 잘못한거라도 있나요?
아니면 데이타가 깨져 버린걸까요?

    intLength :=intLength-length(ClientSocket1.Socket.ReceiveText);
        if read = 0 then begin
            if intLength > 0 then begin
                GetMem(Buffer,initLength);
                ZeroMemory(Buffer,initLength);
                strcat(buffer,pCHar(ClientSocket1.Socket.ReceiveText));
            end else if intLength <= 0 then begin
                GetMem(Buffer,initLength);
                ZeroMemory(Buffer,initLength);
                strcat(buffer,pCHar(ClientSocket1.Socket.ReceiveText));
                stream1 := Tmemorystream.Create;
                stream1.WriteBuffer(buffer, initLength);
                stream1.SaveToFile('d:bbb.jpg');
                freeMem(buffer);
            end;
        end else begin
            if intLength > 0 then begin
                strcat(buffer,pCHar(ClientSocket1.Socket.ReceiveText));
            end else if intLength <= 0 then begin
                strcat(buffer,pCHar(ClientSocket1.Socket.ReceiveText));
                stream1 := Tmemorystream.Create;
                stream1.WriteBuffer(buffer, initLength);
                stream1.SaveToFile('d:aaa.jpg');
                freeMem(buffer);
                stream1.Free;
            end;
        end;
     Inc(Read);
0  COMMENTS