I am working on my server class (for the N+) and I always get an exception with the following code:
public byte[] Receive(int size) { byte[] result = null; if (allow) using (Socket socket1 = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)) { socket1.Bind(new IPEndPoint(IPAddress.Any, _port)); socket1.Listen(10); using (Socket socket2 = socket1.Accept()) { int totalBytesReceived = 0; int availableByteCount = 0; do { availableByteCount = socket2.Available; if (availableByteCount > 0) { totalBytesReceived += availableByteCount; result = new byte[size]; int readByteCount = socket2.Receive(result, result.Length, SocketFlags.None); } } while (availableByteCount > 0); } } return result; }It happens after sending data a lot of times, or if I send it too fast.
The exception on N+'s side reads : "An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll"
On my C# Form app the exception reads: "An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll"
Anyone know how I can fix it?
Thanks