Setting up TCP server with Wifi RN171

Hi,

I am trying to create a TCP server with Wifi RN171. I checked the baud rate. It has default value which is 9600. Though,I managed to establish enable the server. The problem that I found is that when I try to send the respond to the request received.

When I send the http request from my phone (windows phone) though internet explorer. It works find, but when I try to connect to the server that I setup with other devices including different internet browsers on laptops. I got the timeout response. I also tried to connect to the server with another Gadgeteer device and I debugged it. It seems that the response that I got is null which is really strange.

void customeWifi_HttpRequestReceived(GTM.GHIElectronics.HttpStream request)
        {
            string requestedURL = request.Request.URL;

            if (requestedURL == "/index.html")
            {
                byte[] document = System.Text.Encoding.UTF8.GetBytes("<html><head></head><body>HELLO world littleting</body></html>");

                request.Response.HeaderData["Content-type"] = "text/html";
                request.Response.HeaderData["Connection"] = "close";
                request.Response.HeaderData["Cache-Control"] = "no-cache";
                request.Response.HeaderData["Content-Length"] = document.Length.ToString();
                request.Response.StatusCode = GTM.GHIElectronics.HttpResponse.ResponseStatus.OK;

                //All you have to do is send the document data through the response object.
                //Header data is automatically applied for you when you chose to send.
                
                request.Response.Send(System.Text.Encoding.UTF8.GetBytes("<html><head></head><body><h1>HELLO world littleting</h1></body></html>"));
                
            }

            Debug.Print("Finish responding to request");
        }

What did I do wrong? Previously it wasn’t working on any devices or computer at all, but after I added this line:



It started to work on IE (sometime though). Also the server seems to be very unstable. I got automatically disconnected several times.

Just to add some information for you. I tried to do as what mentioned in this link: https://www.ghielectronics.com/community/forum/topic?id=12286&page=1

Thank you very much.
1 Like

@ littleting - Are you using our WiFi RN-171 Module or another such as an RN-171 with the XBee footprint (WiFly)? The baudrate should be defaulted to 115200 with our module.

Are you connecting to the HotSpot feature or are you connecting to an existing network?
At what point does it time-out if you use the networking tools in your browser? Also, you should not do:

 document = System.Text.Encoding.UTF8.GetBytes("<html><head></head><body>HELLO world littleting</body></html>");

                request.Response.HeaderData["Content-Length"] = document.Length.ToString();

                //All you have to do is send the document data through the response object.
                //Header data is automatically applied for you when you chose to send.
                
                request.Response.Send(System.Text.Encoding.UTF8.GetBytes("<html><head></head><body><h1>HELLO world littleting</h1></body></html>"));

Here, you are telling the browser that your data is 61 bytes when it is actually 70 bytes, so the browser will insist that the transaction is complete with this string:

[em]

HELLO world littleting

</bod[/em]