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

Nevyn's SimpleWebServer Translated to VB


  • Please log in to reply
27 replies to this topic

#21 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 17 December 2011 - 02:58 AM

Mark, Have you tried to host silverlight (.XAP) files with your server? I can't seem to make a connection between the silverlight and the webserver. The problem seems to be on the clientaccesspolicy.xml. I am able to download the policy on port 943 with no problems. The issue is when the silverlight applications sends the request: <policy-file-request/> I respond to this request by sending the policy file but no matter what I try, the silverlight application has an error 10013 (Access Denied) on the connect routine. This is really frustrating!

#22 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 17 December 2011 - 06:41 AM

Have you tried to host silverlight (.XAP) files with your server?

I can't seem to make a connection between the silverlight and the webserver. The problem seems to be on the clientaccesspolicy.xml. I am able to download the policy on port 943 with no problems. The issue is when the silverlight applications sends the request: <policy-file-request/> I respond to this request by sending the policy file but no matter what I try, the silverlight application has an error 10013 (Access Denied) on the connect routine.

This is really frustrating!

I know what you mean - I hit exaclty the same problem when I tried it. You can find my solution in this thread (it's C# but there are some free translation sites around - I believe that Telerik have one).

You can also find some more information on my blog. I also used this as the basis for my data logger example.

Hope this help,
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#23 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 17 December 2011 - 04:17 PM

I know what you mean - I hit exaclty the same problem when I tried it. You can find my solution in this thread (it's C# but there are some free translation sites around - I believe that Telerik have one).

You can also find some more information on my blog. I also used this as the basis for my data logger example.

Hope this help,
Mark


Mark,

Your blog is great!

I have been through the forum topic you referenced many times... I will try some more. Obviously I am missing something.

Here is where I capture the request (on the xml policy port - 943)
Private Sub ProcessRequest(ByVal client As Socket, ByVal request As String)
        If request Is Nothing Then
            Debug.Print("Request is nothing...")
            Exit Sub
        End If

        If request = "<policy-file-request/>" Then
            SendFile(client, "/clientaccesspolicy.xml")
            Exit Sub
        End If
        Dim firstLine As String()

        firstLine = request.Substring(0, request.IndexOf(vbLf)).Split(" "c)
        If firstLine(0).ToLower() <> "get" Then
            Send(client, HTTP_501_NOT_IMPLEMENTED)
        Else
            If firstLine(2).ToLower() <> "http/1.1" & vbCr Then
                Send(client, HTTP_505_HTTP_VERSION_NOT_SUPPORTED)
            Else
                SendFile(client, firstLine(1))
            End If
        End If
    End Sub

Here is the send file:

  Private Sub SendFile(ByVal client As Socket, ByVal file__1 As String)
        If (file__1.Length > 14) AndAlso (file__1.Substring(0, 14).ToLower() = "/command.html?") Then
            ProcessCommand(client, file__1.Substring(14))
        Else
            Dim fullPath As String
            Dim fileNameComponents As String()

            fileNameComponents = file__1.Split("/"c)
            fullPath = _webRoot
            For Each fnc As String In fileNameComponents
                If fnc.Length > 0 Then
                    fullPath += "\" & fnc
                End If
            Next
            Debug.Print("File requested: " & fullPath)
            If File.Exists(fullPath) Then
                Dim fileType As String

                '#Region "Work out the file type"

                Dim period As Integer

                period = fullPath.LastIndexOf("."c)
                fileType = Nothing
                If period > 0 Then
                    Select Case fullPath.Substring(period + 1).ToLower()
                        Case "html"
                            fileType = "text/html"
                            Exit Select
                        Case "css"
                            fileType = "text/css"
                            Exit Select
                        Case "js"
                            fileType = "text/javascript"
                            Exit Select
                        Case "xap"
                            fileType = "application/x-silverlight-app"
                            Exit Select
                        Case "xml"
                            fileType = "text/xml"
                            Exit Select
                        Case "jpg"
                            fileType = "image/jpeg"
                            Exit Select
                        Case "gif"
                            fileType = "image/gif"
                            Exit Select
                    End Select
                End If

                '#End Region

                '#Region "Send the file"

                If fileType IsNot Nothing Then
                    Debug.Print("Sending file " & fullPath)
                    Using fs As New FileStream(fullPath, FileMode.Open)
                        Dim amountRead As Integer
                        Dim buffer As Byte()

                        Send(client, "HTTP/1.0 200 OK" & vbCr & vbLf & "Content-Type: " & fileType & "; charset=utf-8" & vbCr & vbLf & "Content-Length: " & fs.Length.ToString() & vbCr & vbLf & vbCr & vbLf)
                        buffer = New Byte(SEND_BUFFER_SIZE - 1) {}
                        amountRead = fs.Read(buffer, 0, SEND_BUFFER_SIZE)
                        While amountRead <> 0
                            client.Send(buffer, amountRead, SocketFlags.None)
                            amountRead = fs.Read(buffer, 0, SEND_BUFFER_SIZE)
                        End While
                    End Using
                Else
                    Send(client, HTTP_415_UNSUPPORTED_MEDIA_TYPE)

                    '#End Region
                End If
            Else
                Send(client, HTTP_404_PAGE_NOT_FOUND)
            End If
        End If
    End Sub

And this is my xml:
<?xml version="1.0" encoding="utf-8"?>
<access-policy>
<cross-domain-access>
<policy>
<allow-from http-request-headers="SOAPAction">
<domain uri="*"/>
</allow-from>
<grant-to>
<resource path="/" include-subpaths="true"/>
</grant-to>
</policy>
</cross-domain-access>
</access-policy>


There is nothing exotic about any of this as far as I can tell.

I am trying to track down the /0 termination mentioned in the forum... but, as far as I can tell, I don't have this in my file.


-terry

#24 seascan

seascan

    Advanced Member

  • Members
  • PipPipPip
  • 88 posts

Posted 17 December 2011 - 05:05 PM

Mark, All this time I thought the problem was in the server! In my silverlight code I was trying to use sockets: 'endPoint = New DnsEndPoint("192.168.1.160", 4503) 'Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) 'Dim args As New SocketAsyncEventArgs() 'args.SocketClientAccessPolicyProtocol = SocketClientAccessPolicyProtocol.Tcp 'args.UserToken = Socket 'args.RemoteEndPoint = EndPoint 'AddHandler args.Completed, New EventHandler(Of SocketAsyncEventArgs)(AddressOf OnConnect) 'Socket.ConnectAsync(args) When I switched to your method of "WebClient" it all worked! But, for my own education, do you know if when using sockets and the policy request comes in on 943 does the policy get sent back on 943 or does it go through the new socket (4503 in the case above)? I really appreciate all the stuff you post... it is inspiring.

#25 Nevyn

Nevyn

    Advanced Member

  • Members
  • PipPipPip
  • 1072 posts
  • LocationNorth Yorkshire, UK

Posted 17 December 2011 - 09:15 PM

But, for my own education, do you know if when using sockets and the policy request comes in on 943 does the policy get sent back on 943 or does it go through the new socket (4503 in the case above)?

The request for the policy file and the response are both served through port 943.

Glad you liked the posts. I started a Codeplex project for the web server and Silverlight code back in September - I really must get around to bringing all the latest code and documentation together on this project.
Mark

To be or not to be = 0xFF

 

Blogging about Netduino, .NET, STM8S and STM32 and generally waffling on about life

Follow @nevynuk on Twitter


#26 Bryan T

Bryan T

    Member

  • Members
  • PipPip
  • 25 posts

Posted 13 June 2012 - 02:35 PM

Baxter, I've been playing with this webserver for several weeks. Thanks for translating it. I've been able to do everything I have needed to do except that I can't seem to get it to serve up a file, except html. This includes any graphics called by the html as well as any text files that I try to bring in through ajax. Everything appears to work on the netduino side, but I don't see any results in the browser. Do you have any ideas?

#27 baxter

baxter

    Advanced Member

  • Members
  • PipPipPip
  • 415 posts

Posted 13 June 2012 - 08:18 PM

Hi Brian,

I have been working on a smart shield for Netduino Plus using a Picaxe 20x2 to handle I2C and 1-wire tasks so I haven't paid much attention to the port of Nevyn's webserver.
It has gone through several iterations. I modified it to process standard URL encoded GET, POST requests, e.g.
http://192.168.0.130:80/netduino?SetTime="" (sets time from NIST Daytime Client)

http://192.168.0.130:80/netduino?SDvolinfo="" (SD volume Info)

http://192.168.0.130:80/netduino?SDdownload=SD\ABC\Big5.htm (download Big5.htm to browser)

http://192.168.0.130:80/netduino?enableserial="COM1" (enable Netduino COM1 serial port, blocking)
I also wrote a VB Windows client to act as a command processor that has a web browser and uses the WebClient class to upload/download files , a serial terminal to talk to the
Netduino serial port and MFDeploy to monitor debug output.

Your post prompted me to return to this and I discovered a disaster. I cannot compile any project under the Visual Studio 2010 root. All of the files seem to have been marked as
system files. I think I caused this by by copying the C:\users\baxter\documents folder to a backup USB hard drive. I will upload the client and webserver for you in this thread
after I get everything fixed. I don't whether this will fix your problem. The WebClient class has the capability to save the downloaded file to disk.

Baxter

#28 Bryan T

Bryan T

    Member

  • Members
  • PipPip
  • 25 posts

Posted 18 June 2012 - 04:20 PM

Baxter, I don't know if the update will fix my particular problem, but I like what you're saying. I look forward to seeing what you have whenever you get it fixed. Bryan




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.