I am having an issue with receiving socket connection on my Netduino 3 Ethernet; “Connection Refused”. My code has been used in the past successfully on a Netduino 2 Plus but does not work on this newer board. Currently my code is blocking at the listening socket Accept call; waiting for a connection. I have my board configured for a static IP and the code is the following for accepting a socket connection. Any help would be appreciated.
try
{
_listeningSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, this.Port);
_listeningSocket.Bind(ipEndPoint);
_listeningSocket.Listen(1);
while (true)
{
_sessionSocket = _listeningSocket.Accept();
if (_sessionSocket != null)
{
if (_sessionSocket.Poll(-1, SelectMode.SelectRead))
{
objWebSession = new WebSession(_sessionSocket, this);
WebSessions.Add(objWebSession);
Debug.Print("Web Session Created");
DebugInfo.PrintDebugInfo("Web Session Created");
objWebSession.Start();
}
}
foreach (WebSession objWebSessionItem in WebSessions)
{
if (objWebSessionItem != null)
{
if (objWebSessionItem._Completed == true)
{
WebSessions.Remove(objWebSessionItem);
Debug.Print("Remove Web Session");
}
}
}
}
}
catch( Exception ex )
{
Debug.Print("Web Server Exception Error" + ex.Message);
DebugInfo.PrintDebugInfo("Web Server Exception Error" + ex.Message);
}