wiz750sr 모듈로 테스트 중입니다.
이더넷을 통해 TCP 연결과 연결해제를 반복하다보면 Ping 은 통신이 되는데 Connection 이 실패 합니다.
(Wizconfig Tool 의 Device Search 에도 잡히지 않습니다.)
전원을 해제 후 다시 연결 하면 정상 동작하지만 같은 현상이 계속 발생합니다.
와이어 샤크 패킷 캡처로 확인하면 RST 패킷을 받습니다.
테스트에 사용된 간단한 의사 코드는 다음과 같습니다.
while(true)
{
새로운 Socket 생성
소켓비동기 연결
소켓 연결상태 확인
소켓 종료
}
아래는 테스트 중인 코드로 C#코드상에 문제인지 확인하기 위해 계속 변경하면서 테스트 하고있습니다.
static public void Test()
{
int port = 5000;
Socket soc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint endPoint = new IPEndPoint(IPAddress.Parse("192.168.0.2"), port);
try
{
soc.LingerState = new LingerOption(true, 0);
IAsyncResult result = soc.BeginConnect(endPoint, null, null);
result.AsyncWaitHandle.WaitOne(50, false);
if (soc.Connected)
{
if(count % 100 == 0)
Console.WriteLine(count + " Success");
}
else
{
Console.WriteLine(count + " Fail");
}
//soc.EndConnect(result);
}
catch (Exception ex)
{
Console.WriteLine(count + " " + ex.Message);
}
finally
{
if (soc != null)
{
//soc.Shutdown(SocketShutdown.Both);
if(soc.Connected)
soc.Disconnect(true);
soc.Close();
soc.Dispose();
soc = null;
}
}
count++;
}
}