저같은 초보자가 또있으리라 보고 문제를 같이 해결하고자 이글을
남깁니다.
지금 새벽 02 : 30 분
1차 성공을 하였지만 문제가 여전히 남아 있어 저와같은 초보 여러분끼리
같이 도움을 주고 받았으면 합니다.
pk66430@hanmir.com
일단 관심 있으신분은 일단 테스트먼저
폼에 160*120 image1 으로 하나 올려놓고요!
StatusBar1 올리고 Panels[0] Panels[1] 만들고요
ClientSocket1 을 올려놓고
Address : 211.113.231.61
Port : 8985
당연히 ctNonBlocking 이고요
소스 컴파일
unit Client_s;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ScktComp, StdCtrls, ExtCtrls, ComCtrls,JPEG;
type
TForm1 = class(TForm)
Image1: TImage;
ClientSocket1: TClientSocket;
StatusBar1: TStatusBar;
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent; var ErrorCode: Integer);
procedure ClientSocket1Read(Sender: TObject; Socket: TCustomWinSocket);
procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
MS: TMemoryStream;
TotalSize : integer=0;
MsSize : Integer=0;
DataChk : Boolean;
implementation
{$R *.DFM}
procedure TForm1.FormCreate(Sender: TObject);
begin
Button1.Caption:='테스트 카메라 연결';
MS:= TMemoryStream.Create;
ClientSocket1.Open;
end;
//==============================================================================
//
//
// 클라이언트 소켓
//
//
//==============================================================================
procedure TForm1.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
StatusBar1.Panels[1].Text:='Connect';
end;
procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
StatusBar1.Panels[1].Text:='Disconnect of ';
end;
procedure TForm1.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
StatusBar1.Panels[1].Text:='ErrorCode = '+inttostr(ErrorCode);
ErrorCode:=0;
//ClientSocket1.Close;
end;
procedure TForm1.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
var Size : integer;
JPG : TJpegImage;
Data : Array[0..64000] of Byte;
begin
try
Size :=Socket.ReceiveLength;
Size := Socket.ReceiveBuf(Data[0],Size);
TotalSize:=TotalSize+Size;
Ms.WriteBuffer(Data[0] ,Size);
if MSSize = 0 then begin
Ms.Position:=0;
Ms.Read(MsSize,4);
end;
if TotalSize > MsSize then
begin
Ms.Position:=4;
try
JPG := TJpegImage.Create;
Jpg.LoadFromStream(Ms);
Image1.Picture.Assign(Jpg);
Image1.Repaint;
Jpg.Free;
except
exit;
end;
//Socket.SendText('True');
StatusBar1.Panels[0].Text:=IntToStr(MsSize)+':'+IntToStr(TotalSize);
StatusBar1.Panels[1].Text:='정상처리';
end;
finally
MS.Clear;
TotalSize:=0;
MsSize:=0;
end;
end;
procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
if CanClose then ClientSocket1.Close;
end;
end.