I use a mini HTTP server on my FezDuino board and I try to upload files from client.
Every time a WiFi disconnection occured while reading the bytes of the stream.
WiFi configuration is :
WiFiNetworkInterfaceSettings wifiSettings = new WiFiNetworkInterfaceSettings()
{
Ssid = "WiFiWebServerSample",
Password = "0123456789",
Address = IPAddress.Parse("192.168.0.20"),
SubnetMask = IPAddress.Parse("255.255.255.0"),
DhcpEnable = true,
DynamicDnsEnable = true,
Mode = WiFiMode.AccessPoint
};
I launch web server like as below :
webServer = new HttpListener("http");
webWorkerThread = new Thread(() =>
{
while (webServer.IsListening)
{
try
{
HttpListenerContext context = webServer.GetContext();
ProcessInboundGetRequest(context);
}
catch (Exception)
{
Debug.WriteLine("Failed to read context");
}
}
});
And I manage the HTTPRequest to upload like this :
private static void ProcessInboundGetRequest(HttpListenerContext context)
{
try
{
switch (context.Request.HttpMethod.ToUpper())
{
case "POST":
switch (context.Request.RawUrl.ToUpper())
{
case "/UPLOAD":
Stream str = context.Request.InputStream;
buffer = new byte[CHUNKS];
int count = 1, total = 0;
Debug.WriteLine("Upload file is progress...");
while (count > 0)
{
count = str.Read(buffer, 0, CHUNKS);
Debug.WriteLine("(" + count + " bytes read)");
total += count;
}
Debug.WriteLine("Upload file is successful : " + total + " bytes read");
break;
}
}
}
finally
{
context.Response.OutputStream.Close();
}
}
Of course I can join the project files with index.html for testing.
The form used for this example is :
<form id="myForm" action="/upload" enctype="multipart/form-data" method="post">
<label class="custom-uploader" for="file">Upload Your File</label>
<input id="file" accept=".ghi,.tca" name="fileToUpload" type="file" />
<br><button class="btn btn-success" name="submit" type="submit">Upload File</button>
</form>
I try to read the HTTP request stream slower with Thread.Sleep(10) and it seems I succes read more bytes but the WiFi conenction is always ended before reading the end of uploaded file.
Have you any ideas about this problem ?
I have exactly the same problem when I upload a file via a FTP server. I think the problem is around the opened stream…