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

HttLibrary V3

Http Library Sockets Request Response

  • Please log in to reply
8 replies to this topic

#1 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 29 June 2013 - 02:02 PM

Hello EveryOne,

 

I have updated my HttpLibrary to Version 3 which am planning to update allways since it is more freindly than the previous Versions...

 

Library Description:

[color=#800080;]HttpLibrary V.3 is a reimplementation of [color=#0000ff;][color=#0000ff;]the HTTP library V2[/color][/color] with more features like getting the request method and parsing query string, till now it only handles GET methods, soon it will handle POSTS and an FTP will be available TOO![/color][color=#800080;], you will find this library similar to an asp.net standard website in terms of Responses and Requests.[/color]

 

To download the library click on this link, it comes with documentation and an example project

http://softelectrotech.com/?p=622

 

 



#2 JoopC

JoopC

    Advanced Member

  • Members
  • PipPipPip
  • 148 posts

Posted 29 June 2013 - 04:49 PM

I want to ask you, did you test your program with large data strings (10k+) send from your browser to the Netduino with a $ajax call?

Can you test your code with a string of 10,000 byte's... or something like that?

 

I have the experience that strings more than 500 bytes send to the netduino does not work for me. And I have programmed it almost the same as you did.



#3 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 29 June 2013 - 11:12 PM

Hello JoopC,

Thanks for your note :) actually i am planning to optimize it more and more in the near future with new functionalities, but this release is just a re-implementation  of the V2 library, and i found it more user friendly than V2, till now it does not handle 10,000 bytes of ajax but hopefully with time it will :)

thanks :)



#4 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 06 July 2013 - 03:07 PM

Hello Nart,

 

First, thanks for the great library, it was exactly what I needed! However, I did run into a few small problems while using it. First, your redirecting function was accidentally hard-coded with Goolge as the target:

public void Redirect(string Url)        {            string rs = "<meta http-equiv="refresh" content="0; url=http://www.google.com">";            byte[] databytes = UTF8Encoding.UTF8.GetBytes(rs);            this.connection.Send(databytes, 0, databytes.Length, SocketFlags.None);        }

It also doesn't send a header when called, so my browser treated it as plain text. To fix that, I modified it a little like this:

public void Redirect(string Url)        {            string rs = "<meta http-equiv="refresh" content="0; url=" + Url + "">";            byte[] headerbytes = UTF8Encoding.UTF8.GetBytes(HtmlPageHeader + "; charset=utf-8rnContent-Length: " + rs.Length.ToString() + "rnrn");            byte[] databytes = UTF8Encoding.UTF8.GetBytes(rs);            connection.Send(headerbytes, 0, headerbytes.Length, SocketFlags.None);            connection.Send(databytes, 0, databytes.Length, SocketFlags.None);        }

Similarly, the Write function doesn't send a header, so the HTML content sent also rendered as plain text, so I added the header there as well:

 public void Write(string Str)        {	    byte[] Data = UTF8Encoding.UTF8.GetBytes(Str);            int datalength = Data.Length;            byte[] HEADER = UTF8Encoding.UTF8.GetBytes(HtmlPageHeader + "; charset=utf-8rnContent-Length: " + datalength.ToString() + "rnrn");            connection.Send(HEADER, 0, HEADER.Length, SocketFlags.None);            int i = 0;            while (datalength > 256)            {                connection.Send(Data, i, 256, SocketFlags.None);                i += 256;                datalength -= 256;            }            connection.Send(Data, i, datalength, SocketFlags.None);        }

Lastly, I was having problems with GET variables, I was getting false positives. For instance, if I asked for the following URL:

http://myserver.com/test.htm?r=5

This would happen:

Debug.Print(request["t"]);//Output ==> 5

It turns out, the function to parse GET variables was finding the "t" in "test.htm" and then finding "=" and putting them together. So I modified it a little bit using RegEx to only match the full requested value. It also saves a little time, and becomes a bit more robust, by only looking at the first line of the request, since that's the only line where GET variables should be.

 public string this[string value]        {            get            {                string firstLine = request_buffer.Substring(0, request_buffer.IndexOf("rn"));                int IndexOfAndOrSpace;                Match contains = Regex.Match(firstLine, @"[?,&]" + value + "=");                if (contains.Success)                {                    int IndexOfValue = firstLine.IndexOf(contains.Value);                    for (IndexOfAndOrSpace = IndexOfValue + 1; firstLine[IndexOfAndOrSpace] != '&' && firstLine[IndexOfAndOrSpace] != ' '; IndexOfAndOrSpace++) ;                    int Length = IndexOfAndOrSpace - (IndexOfValue + contains.Length);                    return firstLine.Substring(IndexOfValue + contains.Length, Length);                }                else                    return null;            }

For personal use, I also worked in MIME types for CSS, .png files, XML, JavaScript files, and JASON, as well as cookie support (for simple cookie based authentication) and the ability to leverage browser caching to lessen the server load for repeated requests. If anyone is interested, just let me know and I'll be happy to share that code.

 

Anyway, thanks again for the great library! I hope these suggestions prove helpful.



#5 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 06 July 2013 - 08:16 PM

Hello ShVerni,

 

Well Thanks Alot For Reminding me about these errors :) Really appreciate that, and yes am fixing the library right now and within these few days i am releasing a new one with all these bugs fixed plus am adding the ability of using an external ram for the recieving buffer hence making more ram space ...

 

Thanks again :)



#6 ShVerni

ShVerni

    Advanced Member

  • Members
  • PipPipPip
  • 138 posts
  • LocationNew York, New York

Posted 07 July 2013 - 02:35 AM

Oooh, I look forward to your new release, especially with that external RAM, can't wait! :D



#7 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 08 July 2013 - 06:17 PM

Hello All,

The library was updated and fixed a couple of bugs, thanks to ShVerni :)

Below are the list of changes :

 

[color=#ff0000;]Bug fixes :[/color]

[color=#ff0000;]1) fixed the request[string] which returned a flase negative (fixed)[/color]

[color=#ff0000;]2) fixed the redirect , now it redirects to any url (fixed)[/color]

[color=#ff0000;]3) polling was added on receiving , which provoked many errors (fixed)[/color]

[color=#ff0000;]4) fixed the write functions by adding two new ones[/color]

 

[color=#008000;]Changes:[/color]

[color=#008000;]1) removed receive buffer size and send buffer size from constructor, recieve depends on the request size[/color]

[color=#008000;]2) added a proprtie which sets the send buffer size (default is 256)[/color]

[color=#008000;]3) added two new Write functions to the response:[/color]

[color=#008000;]Write(string val, string header) & Write(byte[] data, byte[] header)[/color]

[color=#008000;]now you can send a custom header.. followed by the data html...[/color]

[color=#008000;]4) updated the example program.[/color]

[color=#008000;]5) updated the documentation[/color]

 

[color=#0000ff;]to use the new example :[/color]

[color=#0000ff;]1) download the [/color][color=#0000ff;]Library And Example[/color]

[color=#0000ff;]2) copy the html files inside the "copy to memory card folder " to your mmc[/color]

[color=#0000ff;]3)insert your mmc[/color]

[color=#0000ff;]4)modify your connection parameters in the main program[/color]

[color=#0000ff;]5)deploy[/color]

 

Download the Updated Version Here

Next Version Will contain the Serial ram feature which am integrating right now , hence it will save alot of ram so stay tuned .

Thank You :)



#8 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 14 July 2013 - 08:32 PM

Hello All,

Check Out The New Version Of The HttpLibrary V.3.1 which now supports an external ram for handling requests,

many changes where done to the previous version, an example project is available along with the library.

 

Download this library here



#9 Nart Schinackow

Nart Schinackow

    Advanced Member

  • Members
  • PipPipPip
  • 38 posts
  • LocationLondon

Posted 03 August 2013 - 12:40 PM

Hello All,

 

[color=#800080;]This is a new update for the HttpLibrary, now you could load big large pages, css, javascript, and many image types.[/color]

[color=#800080;]Changes :[/color]

[color=#800080;]1) Dhcp is Now Enabled [/color]

[color=#800080;]2) Added HttpUtility Class Which Will Generate Mime Type Headers For Many File Types, which facilitates the creation of headers[/color]

[color=#800080;]3) Changed The Example To Display A Bootstrap Page Linked in the attachement [/color]

[color=#800080;]4) Updated Documentation[/color]

[color=#800080;]5) General Enhancements[/color]

[color=#800080;]6) Added a constructor to Configuration(int) (dhcp use)[/color]

[color=#800080;]7) performance optimized[/color]

 

[color=#800080;]Download The Example And The Library Here[/color]

 

 

 

Posted Image







Also tagged with one or more of these keywords: Http, Library, Sockets, Request, Response

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.