WEBSERVER EXTENSION FOR FEZ COBRA using SD Card help

I tried that, but the compiler red flagged it and said cannot implicitly convert byte[] to string


e.Response = Resource.GetBytes(Resource.BinaryResources.index1);

Currently this is it, but the compiler does not like it



private static void swfForm(object sender, WebServer.EventCallbackEventArgs e)
{
      Debug.Print("Swf Fired");

      e.Response = Resource.GetBytes(Resource.BinaryResources.index1);
      e.ResponseContentType = "application/x-shockwave-flash";
}


Try


e.Response = Resource.GetBytes(Resource.BinaryResources.index1).ToString();

@ ianlee74, it took that. But when i tried to access that page it did not work.

I have been trying to use the WEBSERVER EXTENSION FOR FEZ COBRA example
[url]http://code.tinyclr.com/project/243/webserver-extension-for-fez-cobra/[/url]

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";
        }
    }
}


What if you “embed” this swf file inside normal html and call normal html code?

no can do, there are several files that call one another.

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…

So, I have updated the webserver class. http://code.tinyclr.com/project/243/webserver-extension-for-fez-cobra/

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?

Thanks

Thanks, i get an error when trying to load the web page. below are my events.


        private static void indexForm(object sender, WebServer.EventCallbackEventArgs e)
        {
            Debug.Print("Indx Fired");
            e.Response = Resources.GetString(Resources.StringResources.index);
            e.ResponseContentType = "text/html";
        }

        private static void analyseForm(object sender, WebServer.EventCallbackEventArgs e)
        {
            Debug.Print("SwfFired");
            e.BinaryResponse = Resources.GetBytes(Resources.BinaryResources.index1);
            e.ResponseContentType = "application/x-shockwave-flash";
        }


I am not good with the debug output, but here it is if it helps


1
Indx Fired
    #### Exception System.ArgumentException - 0x00000000 (3) ####
    #### Message: 
    #### System.Resources.ResourceManager::.ctor [IP: 0014] ####
    #### System.Resources.ResourceManager::.ctor [IP: 000d] ####
    #### TestConsole.Resources::get_ResourceManager [IP: 0020] ####
    #### TestConsole.Resources::GetString [IP: 0004] ####
    #### TestConsole.Program::indexForm [IP: 0011] ####
    #### FastloadMedia.NETMF.Http.WebServer::ThreadProc [IP: 0283] ####
A first chance exception of type 'System.ArgumentException' occurred in mscorlib.dll
    #### Exception System.Net.Sockets.SocketException - CLR_E_FAIL (4) ####
    #### Message: 
    #### Microsoft.SPOT.Net.SocketNative::poll [IP: 0000] ####
    #### System.Net.Sockets.Socket::Poll [IP: 0011] ####
    #### System.Net.Sockets.Socket::Accept [IP: 0017] ####
    #### System.Net.HttpListener::AcceptThreadFunc [IP: 0020] ####
    #### SocketException ErrorCode = -1728053248
    #### SocketException ErrorCode = -1728053248
A first chance exception of type 'System.Net.Sockets.SocketException' occurred in Microsoft.SPOT.Net.dll
    #### SocketException ErrorCode = -1728053248
    #### SocketException ErrorCode = -1728053248
The thread '<No Name>' (0x4) has exited with code 0 (0x0).
Exception was thrown: System.ArgumentException
The program '[2] Micro Framework application: Managed' has exited with code 0 (0x0).



It fails on GetString in indexForm event handler.

In your previous example, your string was named index1 and swf was named .index. Now it is opposite… Can you verify your resources?

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,
        }


Is it possible to e-mail your test project in a zip/rar file to me?

My shortest mail: housy [at] telenet [dot] be (hmm I think spam-bots already know how to parse this kind of notation anyway :slight_smile: )

sent

It seems the heart of the change are these.

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 :slight_smile:

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…

You can force Internet Explorer to redownload a page, even if it’s cached, by pressing CTRL+F5.

You can force Internet Explorer to redownload a page, even if it’s cached, by pressing CTRL+F5.

Should work in Firefox too.

in FF i think it’s CTRL-R