I have been struggling with the ND+ and sockets. I used the code from http://www.element14...uino-web-server to setup my ND+ to listen for requests on a socket and to change LEDs sequences depending on the request. Without a lot of detail I would like to tell you the problem first since it may save a lot of reading.
The ND+ listens on a socket and works sometimes but it will always fail eventually or even right away.
[color=#ff0000;]The error I receive is "No connection could be made because the target machine actively refused it".[/color]
I have used MFDeploy to setup a static IP and I even used a line in code to set the IP statically but neither seem to matter.
Like I said, sometimes it works and sometimes it doesn't. I've been racking my brain for days. Is the problem because I am listening on one thread and processing the result on another?
I can ping the device with windows command prompt indefinitely while sending requests. I can even ping the device after the network error shows up but the application on the ND+ is locked up.
The two files attached are:
1. The application that is on the ND+.
2. The dll that is used to talk to the ND+.
To use it just create a forms app and import the dll and you should be able run the program without any peripherals connected to the ND+ except power and a network cable.
Thank you in advance for any helpful information.
Steve
public static void Main()
{
Microsoft.SPOT.Net.NetworkInformation.NetworkInterface.GetAllNetworkInterfaces()[0].EnableStaticIP("10.0.0.206", "255.255.255.0", "10.0.0.1");
Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
socket.Bind(new IPEndPoint(IPAddress.Any, 8080));
socket.Listen(10);
//thread start
ThreadStart threadStart = new ThreadStart(workerThread);
Thread threadWorker = new Thread(threadStart);
threadWorker.Start();
OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
while (true)
{
string rawData = "";
using (Socket commSocket = socket.Accept())
{
while (!commSocket.Poll(10, SelectMode.SelectRead)) ;
led.Write(true);
int bytesSent = commSocket.Available;
if (bytesSent > 0)
{
byte[] bytes = new byte[bytesSent];
int bytesReceived = commSocket.Receive(bytes, bytesSent, SocketFlags.None);
if (bytesReceived == bytesSent)
{
rawData = (new string(Encoding.UTF8.GetChars(bytes)));
}
}
if (rawData == "PhotoOn")
{
sequence = "DMXPhotoOn";
break;
}
else if (rawData == "PhotOff")
{
sequence = "DMXPhotoOff";
break;
}
//start of new LEDController code to seperate passed parameters
else if (rawData != "PhotoOff" || rawData != "PhotoOn")
{
char delimiter = ' ';
string[] words;
words = rawData.Split(delimiter);
sequence = words[0];
red = byte.Parse(words[1]);
green = byte.Parse(words[2]);
blue = byte.Parse(words[3]);
LEDChain = words[4];
}
led.Write(false);
}
}
}