Nevyn's SimpleWebServer Translated to VB
#21
Posted 17 December 2011 - 02:58 AM
#22
Posted 17 December 2011 - 06:41 AM
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).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!
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
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
Posted 17 December 2011 - 05:05 PM
#25
Posted 17 December 2011 - 09:15 PM
The request for the policy file and the response are both served through port 943.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)?
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
Posted 13 June 2012 - 02:35 PM
#27
Posted 13 June 2012 - 08:18 PM
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
Posted 18 June 2012 - 04:20 PM
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users