Hello,
I have code on a fez Cobra (mf 4.1) that I am trying to port over to any of the Gadgeteer boards (Cerb,Hydra, Spider) with mf 4.2.
I have a fairly simple app that reads short messages (@ 10 Bytes) from a serial port, Converts the messages into XML, and writes them to a TCP Socket (@ 1000 bytes).
I have run the cobra for months and not had any issues.
On every single gadgeteer I have the same issue, @ the 1.5 hour mark, the entire system just hangs mid write of my XML (as viewed in teraterm)
Is there something different about the Gadgeteer ethernet or the 4.2 code that I should be aware of?
I have been chasing this for a while now And it is really becoming a project ender for me.
Here is how I am implementing the Ethernet on a Cerberus:
private NetworkInterface _networkInterface = NetworkInterface.GetAllNetworkInterfaces()[0];
private Socket _clientSocket
private Thread _listener;
private void ProgramStarted()
{
//unrelated code goes here
_networkInterface.EnableDhcp();
while (_networkInterface.IPAddress == "0.0.0.0")
{
Debug.Print("Awaiting IP Address");
Thread.Sleep(1000);
}
_hostSocket = new System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
IPAddress hostIP = IPAddress.Parse(_networkInterface.IPAddress);
var localEndPoint = new IPEndPoint(IPAddress.Any, Utility.LISTENING_PORT);
_hostSocket.Bind(localEndPoint);
_hostSocket.Listen(1);
_listener = new Thread(ListenerLoop);
_listener.Start();
}
private void ListenerLoop()
{
while (true)
{
try
{
Debug.Print("listening...");
_clientSocket = _hostSocket.Accept();
}
catch (Exception e)
{
Debug.Print(e.Message);
}
}
}
private void MediumTimer_Tick(Timer timer)
{
var message = GetMessage();
if (_clientSocket != null)
{
_clientSocket.Send(Encoding.UTF8.GetBytes(message));
}
}
Any ideas would be helpful, thanks
Tal