i want to tweak the example to serve up files that i included in my resource folder. From what i can see its serving up the index. html file just fine, but when that page calles the second file index.swf it dies. below is the main code where i just changed the calls it makes for the 2 web resource files.
I cant upload the files here for anyone to try because GHI does not allow even .zip files. ;(
there are just 2 files
index.html which is 2k
index.swf which is 6k
namespace TestConsole
{
public class Program
{
public static void Main()
{
using (WebServer server = new WebServer())
{
server.AddEvent("/", new WebServer.EventCallback(indexForm));
server.AddEvent("/index.swf", new WebServer.EventCallback(swfForm));
// Sleep forever
Thread.Sleep(Timeout.Infinite);
}
}
private static void indexForm(object sender, WebServer.EventCallbackEventArgs e)
{
Debug.Print("Indx Fired");
e.Response = Resources.GetString(Resources.StringResources.index1);
e.ResponseContentType = "text/html";
}
private static void swfForm(object sender, WebServer.EventCallbackEventArgs e)
{
Debug.Print("SwfFired");
e.Response = Resources.GetBytes(Resources.BinaryResources.index).ToString();
e.ResponseContentType = "application/x-shockwave-flash";
}
}
}
The problem is that you convert a binary data to a string. It will truncate to first \0. I will extend the webserver class so you can pass a BinaryResponse. Stay tuned…
You can now use the BinaryResponse property in addition to Response property. As the name implies, BinaryResponse is for sending byte arrays instead of a string.
Can you please give it a try and post the results?
yes, what i did was make a new project as i did not want to change that one. when i added the files this time around the compiler renamed them that way, i have verified this. here is it just for sanity sake.
[System.SerializableAttribute()]
internal enum StringResources : short
{
index = -2501,
}
[System.SerializableAttribute()]
internal enum BinaryResources : short
{
index1 = -1181,
}
So i took these and added them to my original one. Now its working, though i dont know why its not on the one i sent you which was started as a new project.
/// <summary>
/// The binary response to send.
/// Set by event handler (in case of a binary response).
/// </summary>
/// <remarks>If you both set Response and BinaryResponse in one event, only Response will be sent.</remarks>
public byte[] BinaryResponse = null;
and more specifically this…
if ((args.Response != null) || (args.BinaryResponse != null))
{
// Send contenttype
if (args.ResponseContentType != null)
response.ContentType = args.ResponseContentType;
// Send answer to client
if (args.Response != null)
args.BinaryResponse = Encoding.UTF8.GetBytes(args.Response);
response.ContentLength64 = args.BinaryResponse.Length;
using (Stream output = response.OutputStream)
output.Write(args.BinaryResponse, 0, args.BinaryResponse.Length);
responseSent = true;
}
Don’t know what’s wrong. I wanted to debug it but I gave up. Didn’t get my Cobra connected within 30 minutes, those damn 64-bit drivers again
Well glad you’ve found it yourself, did you do a file compare on both? After you have re-applied those changes to the previous version, you should have the same as what I have uploaded…
i did not do a file compare other than with the eyes. Since adding the changes i seen to the old project that now works, so i killed the new project i sent to you.
Thanks again for taking the time to do that. I am learning so much with your code.
I have a really cool project that i will share with the community based on this code of yours.
I hope this code can evolve to be the basis for all who want to have a web server.
I wish i knew more about .netmf so i could be of more help.
I have been using this web server code quite a bit over the past few days. Been working great in firefox. I just tried it in Explorer and page does not even load up at all. Have any ideas why ?
Never Mind…
Before Asking this I tried it 4 times in IE, and even reset the board and it would not load at all. Then i tried it each time with firefox and it loaded. I have both browser’s to dump the cache each time so i know it was not because firefox had it cached. Of course after i send this i tried it again and it worked. go figure…