전원 온 버튼을 클릭 -> 첫번째 120번 아이피를 읽고 active = true 로 활성화 시킴 이때 타이머로 5초간 connect 가 없으면 121번 아이피를 프로젝터 전원 on 하라고 명령을 줍니다.
if ClientSocket1.Active then
ClientSocket1.Active := False;
Sleep(1000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
Timer1.Enabled := True; // 5초 동안 타이머로 연결 유무 첵
-------------------------------------------
타이머 5초 첵 루틴
PnlSec.Caption := IntToStr(5 - ConChkSec);
if ip = ClientSocket1.Socket.RemoteAddress then // 서버에서 5초 이내 보내온 서버 아이피와 클라이언트에서 on 요청한 아이피가 동일하면 정상적으로 통신연결이므로 다음 121번 아이피로 넘어가라
Timer1.Enabled := False
else
begin // 물리적으로 프로젝터가 랜카드나 케이블 이상으로 또는 완전 고장으로 전혀 네트워크 연결이 안되서 5초 이네에 대답이 없을때 에러로 보고 스킵하고 다음거 실행
if (ConChkSec = 5) then
begin
if ip <> ClientSocket1.Socket.RemoteAddress then
begin
ConChkSec := 0;
Timer1.Enabled := False;
Inc(TimerNextARow);
meoLog_send.Lines.Add('----------------------------------------------------------------------------------------- ');
meoLog_send.Lines.Add(' '+ IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : '
+ 'Timer Routine Power All On : 네트워크 연결 상태를 확인하세요! '
+ ip + ' : ' + port);
meoLog_send.Lines.Add('----------------------------------------------------------------------------------------- ');
meoLog_send.Lines.Add(' ');
if TimerNextARow <= (ASG_ComList.RowCount - 2) then
begin
ip := trim(ASG_ComList.Cells[3,TimerNextARow]);
port := ASG_ComList.Cells[4,TimerNextARow];
Sleep(1000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
meoLog_send.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : '
+ 'Timer Routine Power All On for IP And Port -> ' + ip + ' : ' + port);
meoLog_send.Lines.Add(' ');
NextARow := TimerNextARow;
Timer1.Enabled := True;
end;
with ASG_ComList do begin
for i := 1 to RowCount - 2 do
begin
if trim(Cells[3,i]) = ClientSocket1.Socket.RemoteAddress then
begin
CreatePicture(7,i,True,ShrinkWithAspectRatio,0,AdvGrid.haCenter,AdvGrid.vaTop).LoadFromFile('./NO.png');
end;
end
end;
if (BtnAll = 'Y') then
begin
Inc(NextARow);
for i := NextARow to ASG_ComList.RowCount - 2 do
begin
try
ip := ASG_ComList.Cells[3,i];
port := ASG_ComList.Cells[4,i];
meoLog_send.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : ' + 'Disconnect Routine Power All On IP And Port -> '
+ ip + ' : ' + port);
meoLog_send.Lines.Add(' ');
TimerNextARow := i; if ClientSocket1.Active then // 전 생성한 소켓을 false 시킨다
ClientSocket1.Active := False;
Sleep(5000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
ConChkSec := 0;
Timer1.Enabled := True;
except
on e: Exception do
begin
Application.MessageBox(PChar(e.Message), PChar('에러'), MB_ICONERROR + MB_OK);
end;
end;
end;
end;
질문
kanggilnam
안녕하세요 ?
제가 필요해서 socket 통신으로 프로젝터 전원 온오프 를 만들어 보고 있습니다.
------------------------------------------------------------------
상황:
192.168.0.120
192.168.0.121
192.168.0.122
192.168.0.123
4개의 아이피를 보유한 프로젝터가 있습니다.
120번 아이피와, 123번 아이피는 프로젝터가 없습니다.
121,122번 아이피는 프로젝터가 정상적으로 연결되어 있습니다.
----------------------------------------------------------------
전원 온 버튼을 클릭 -> 첫번째 120번 아이피를 읽고 active = true 로 활성화 시킴 이때 타이머로 5초간 connect 가 없으면 121번 아이피를 프로젝터 전원 on 하라고 명령을 줍니다.
if ClientSocket1.Active then
ClientSocket1.Active := False;
Sleep(1000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
Timer1.Enabled := True; // 5초 동안 타이머로 연결 유무 첵
-------------------------------------------
타이머 5초 첵 루틴
PnlSec.Caption := IntToStr(5 - ConChkSec);
if ip = ClientSocket1.Socket.RemoteAddress then // 서버에서 5초 이내 보내온 서버 아이피와 클라이언트에서 on 요청한 아이피가 동일하면 정상적으로 통신연결이므로 다음 121번 아이피로 넘어가라
Timer1.Enabled := False
else
begin // 물리적으로 프로젝터가 랜카드나 케이블 이상으로 또는 완전 고장으로 전혀 네트워크 연결이 안되서 5초 이네에 대답이 없을때 에러로 보고 스킵하고 다음거 실행
if (ConChkSec = 5) then
begin
if ip <> ClientSocket1.Socket.RemoteAddress then
begin
ConChkSec := 0;
Timer1.Enabled := False;
Inc(TimerNextARow);
meoLog_send.Lines.Add('----------------------------------------------------------------------------------------- ');
meoLog_send.Lines.Add(' '+ IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : '
+ 'Timer Routine Power All On : 네트워크 연결 상태를 확인하세요! '
+ ip + ' : ' + port);
meoLog_send.Lines.Add('----------------------------------------------------------------------------------------- ');
meoLog_send.Lines.Add(' ');
if TimerNextARow <= (ASG_ComList.RowCount - 2) then
begin
ip := trim(ASG_ComList.Cells[3,TimerNextARow]);
port := ASG_ComList.Cells[4,TimerNextARow];
Sleep(1000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
meoLog_send.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : '
+ 'Timer Routine Power All On for IP And Port -> ' + ip + ' : ' + port);
meoLog_send.Lines.Add(' ');
NextARow := TimerNextARow;
Timer1.Enabled := True;
end;
end;
end
else
ConChkSec := ConChkSec + 1;
end;
------------------------------------------------------------------------------------------------------
문제점 :
121번 아이파와 122번 아이피에는 정상적으로 프로젝터가 연결되어있습니다.
위의 5초 첵 루틴에 의하여 120번은 연결이 안되어 있으므로 에러를 띄우고 121 번 아이피로 넘어갑니다.
121번 아이피의 프로젝터 전원 on 을 실행하여 정상적으로 on 이 실행됩니다.
121번 아이피의 프로젝터 전원 on 되고 약 20초 후 자동적으로 socket 이 disconnect 됩니다.
socket이 정상적으로 disconnect 되면 다음 122번 아이피를 active 시키려고 하였으나 아무런 반응이 없습니다.
도저히 이해가 안됩니다.
메모장에 아이피를 기록해 놓아서 122 아이피로 active 시켜라고 명령이 수행되었습니다.
ip := ASG_ComList.Cells[3,i];
port := ASG_ComList.Cells[4,i];
meoLog_send.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : ' + 'Disconnect Routine Power All On IP And Port -> '
+ ip + ' : ' + port);
meoLog_send.Lines.Add(' ');
TimerNextARow := i;
if ClientSocket1.Active then // 전 생성한 소켓을 false 시킨다
ClientSocket1.Active := False;
Sleep(5000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
ConChkSec := 0;
Timer1.Enabled := True;
아래는 Disconnect 루틴의 소스 전체입니다.
---------------------------------------------------------------------------------------------------------------
procedure TfrmClient.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
var
i: integer;
begin
Inc(Seqno);
meoLog_receive.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : ' + 'DisConnected IP -> '
+ ClientSocket1.Socket.RemoteAddress + ' : ' + IntToStr(ClientSocket1.Socket.RemotePort));
meoLog_receive.Lines.Add(' ');
with ASG_ComList do begin
for i := 1 to RowCount - 2 do
begin
if trim(Cells[3,i]) = ClientSocket1.Socket.RemoteAddress then
begin
CreatePicture(7,i,True,ShrinkWithAspectRatio,0,AdvGrid.haCenter,AdvGrid.vaTop).LoadFromFile('./NO.png');
end;
end
end;
if (BtnAll = 'Y') then
begin
Inc(NextARow);
for i := NextARow to ASG_ComList.RowCount - 2 do
begin
try
ip := ASG_ComList.Cells[3,i];
port := ASG_ComList.Cells[4,i];
meoLog_send.Lines.Add(' '+IntToStr(Seqno)+').....' + DateTimeToStr(now) + ' : ' + 'Disconnect Routine Power All On IP And Port -> '
+ ip + ' : ' + port);
meoLog_send.Lines.Add(' ');
TimerNextARow := i;
if ClientSocket1.Active then // 전 생성한 소켓을 false 시킨다
ClientSocket1.Active := False;
Sleep(5000);
ClientSocket1.Host := ip;
ClientSocket1.Port := StrToInt(port);
ClientSocket1.Active := True;
ConChkSec := 0;
Timer1.Enabled := True;
except
on e: Exception do
begin
Application.MessageBox(PChar(e.Message), PChar('에러'), MB_ICONERROR + MB_OK);
end;
end;
end;
end;
end;
이 댓글 링크
다른 사이트에 공유하기
8 answers to this question
Recommended Posts
이 토의에 참여하세요
지금 바로 의견을 남길 수 있습니다. 그리고 나서 가입해도 됩니다. 이미 회원이라면, 지금 로그인하고 본인 계정으로 의견을 남기세요.