Q&A

  • 이것좀 봐주세요... ... ... 소켓임다..
server에서 보낼때...



procedure TTTclient.Button2Click(Sender: TObject);

var

ssize : string; //스트림 테이터 사이즈

begin

jpeg_save:=Tjpegimage.Create;

stream:=Tmemorystream.Create;

stream1:=Tmemorystream.Create;

Cap := TBitmap.Create;

Cap.Width := Panel1.Width;

Cap.Height := Panel1.Height;

DC := GetDC(Panel1.Handle);



BitBlt(Cap.Canvas.Handle,0,0,Cap.Width,Cap.Height,DC,0,0,SRCCOPY);



jpeg_save.Assign(cap);

jpeg_save.CompressionQuality:=30;

jpeg_save.Compress;

stream.clear;

stream1.Clear;

jpeg_save.SaveToStream(stream);



send.ku[0] := 'A';

send.ku[1] := 'A';

send.ku[2] := '0';

send.ku[3] := '0';



ssize := inttostr(stream.size); //스트림 사이즈

send.size[0] := ssize[1];

send.size[1] := ssize[2];

send.size[2] := ssize[3];

send.size[3] := ssize[4];



stream1.Write(send,sizeof(send));

stream.Position:=0;

stream1.Position:=0;



memo1.Lines.Add('구분자:---> '+ send.ku + '크기:--- '+send.size);



try

CS.Socket.SendStream(stream1);

CS.Socket.SendStream(stream);

finally



Cap.Free;

ReleaseDC(Panel1.Handle,DC);

jpeg_save.Free;

stream.Free;

stream1.Free;

end;

end;



client에서 받을때..

procedure TF_server.ServerSocket1ClientRead(Sender: TObject;

Socket: TCustomWinSocket);

var

//-----------------------------------

Stream : TMemoryStream;

jpeg_data : TJPEGImage;

//-----------------------------------

recvinBuffer : array[0..7] of char;

recvBuffer : array[0..6000] of char;

//-----------------------------------

Childku, childinfo : string;

Childsize,chk : integer;

appt : BOOL;

//-----------------------------------

begin

//-----------------------------

stream := TMemoryStream.Create;

jpeg_data := TJPEGImage.Create;

appt:= true;

//-----------------------------



while appt do

begin

Socket.ReceiveBuf(recvinBuffer, sizeof(recvinBuffer));

childinfo := recvinBuffer;

Childku := copy(childinfo,1,4);

Childsize := strtoint(copy(childinfo,5,8));

Memo1.Lines.Add('이미지: '+inttostr(Childsize));

//-----------------------------------------------------//

if Childsize > 0 then

begin

//----------------------------------------------

try

Socket.ReceiveBuf(recvBuffer, Childsize);

Stream.Write(recvBuffer, Childsize);

Stream.Position := 0;

jpeg_data.LoadFromStream(stream);

Image1.Picture.Assign(jpeg_data);

finally



Childsize := 0;

jpeg_data.Free;

Stream.Free;

appt := false;

//----------------------------------------------

end;

end;

end;

end;



이렇게 했는데 에러가...



클라이언트에서 이미지 한번 받을때 두번 반복을 하네요..

제가 뭘 잘못했나요...

아무리 해두 이미지가 깨지고.. 혹은 여러번 받고... 에러가 나네요..



몇일째 고민하고 있어요... 좀 봐주세요...



0  COMMENTS