Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Netduino + 2 Webserver crashes


  • Please log in to reply
No replies to this topic

#1 Tal Tikotzki

Tal Tikotzki

    Member

  • Members
  • PipPip
  • 10 posts

Posted 19 December 2012 - 07:04 PM

I was doing some POCs recently testing the Netduino Plus 2 platform for a certain project.

One of the POCs was to test the web-server capability and limitations. I scanned the web and came into several examples of implementing a simple HTTP web server. It seems that the basic implementation is very common:

Socket Listening method which runs on a different thread:
private void RunServer()
{
    listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
    IPEndPoint BindingAddress = new IPEndPoint(IPAddress.Any, LISTEN_PORT);
    listenSocket.Bind(BindingAddress);
    listenSocket.Listen(1);
    IsServerRunning = true;
    while (true)
    {
        acceptedSocket = listenSocket.Accept();
        ProcessRequest();
        acceptedSocket.Close();
    }
}

The processing Method:
 private void ProcessRequest()
        {
            acceptedSocket.Receive(RECEIVE_BUFFER);
            var request = new string(UTF8Encoding.UTF8.GetChars(RECEIVE_BUFFER));
            var HEADER = UTF8Encoding.UTF8.GetBytes(HtmlPageHeader + "text/html" + "; charset=utf-8\r\nContent-Length: " + fileLength.ToString() + "\r\n\r\n");

            acceptedSocket.Send(HEADER, 0, HEADER.Length, SocketFlags.None);
            while (FILE_LENGTH > sendBuffer.Length)
            {
                fileStream.Read(sendBuffer, 0, sendBuffer.Length);
                acceptedSocket.Send(sendBuffer, 0, sendBuffer.Length, SocketFlags.None);
                FILE_LENGTH -= sendBuffer.Length;
            }
            fileStream.Read(sendBuffer, 0, (int)FILE_LENGTH);
            acceptedSocket.Send(sendBuffer, 0, (int)FILE_LENGTH, SocketFlags.None);
            
            fileStream.Close();
        }

let's assume that the ProcessRequest method, always returns the same simple html file (Text and Styles only, no images etc...)

This works okay when a Chrome browser running on a Windows 7 machine is trying to access the pages, click several times (slowly) on the refresh button works as well but:
1. Trying to access the Netduino web server from a chrome running on Android 4.0.4 result many times with Timeout
2. Constantly clicking the Refresh button (F5) of the Chrome@win7 causes an exception on the Netduino, this usually happens after 10-20 requests one after the other.
The exception is:

A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll


On the client side I'm getting:

Chromium's connection attempt to 10.XXX.YYY.55 was rejected.


Any ideas?

Tal




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.