Hi Everyone,
i have FezDomino + Fez ConnectShield and i want to download mp3 files from my server,
(also i am using mp3 shield and a 2x16 lcd display but they are not connected in this test).
it starts downloading, but it is very very slow downloading… i am downloading the same file with my pc in 10 seconds near ~800kb/s but fez connect shield gets it 2kb/s
while downloading, it suddenly cuts the connection in random time… sometimes at 400kb downloaded or 200 kb or event 1.5mb and not giving any error…
here is my wiznet configuration…
byte[] mac = { 0x00, 0x26, 0x1C, 0x7B, 0x29, 0xE8 };
WIZnet_W5100.Enable(SPI.SPI_module.SPI1, (Cpu.Pin)FEZ_Pin.Digital.Di10, (Cpu.Pin)FEZ_Pin.Digital.Di7, true); // WIZnet interface on FEZ Connect
Dhcp.EnableDhcp(mac, "wiznet");
and here is the download class i use…
using System;
using Microsoft.SPOT;
using System.IO;
using GHIElectronics.NETMF.Net;
using GHIElectronics.NETMF.Net.Sockets;
namespace smg.utulity.downloader
{
class downloader
{
public static event Progress onProgress;
public delegate void Progress(long currentSize, long TotalSize, string Filename);
public static event DownloadFinished onDownloadFinished;
public delegate void DownloadFinished(string errMsg);
public static int DownloadFile(String remoteFilename,
String localFilename)
{
string fname = localFilename.Split('\\')[localFilename.Split('\\').Length - 1];
// Function will return the number of bytes processed
// to the caller. Initialize to 0 here.
int bytesProcessed = 0;
// Assign values to these objects here so that they can
// be referenced in the finally block
Stream remoteStream = null;
Stream localStream = null;
WebResponse response = null;
// Use a try/catch/finally block as both the WebRequest and Stream
// classes throw exceptions upon error
try
{
// Create a request for the specified remote file name
WebRequest request = WebRequest.Create(remoteFilename);
if (request != null)
{
// Send the request to the server and retrieve the
// WebResponse object
// request.ContentLength
response = request.GetResponse();
if (response != null)
{
// Once the WebResponse object has been retrieved,
// get the stream object associated with the response's data
remoteStream = response.GetResponseStream();
long total = response.ContentLength;
// Create the local file
localStream = File.Create(localFilename);
// Allocate a 1k buffer
byte[] buffer = new byte[1024];
int bytesRead;
// Simple do/while loop to read from stream until
// no bytes are returned
do
{
// Read data (up to 1k) from the stream
bytesRead = remoteStream.Read(buffer, 0, buffer.Length);
// Write the data to the local file
localStream.Write(buffer, 0, bytesRead);
// Increment total bytes processed
bytesProcessed += bytesRead;
if (onProgress != null) { onProgress(bytesProcessed, total, fname); }
} while (bytesRead > 0);
}
}
if (onDownloadFinished != null) { onDownloadFinished("finished"); }
}
catch (WebException webEx)
{
Debug.Print("Web Exception Occured");
if (webEx.InnerException is SocketException)
{
SocketException sock = webEx.InnerException as SocketException;
Debug.Print("Socket error code: " + sock.ErrorCode.ToString());
}
}
catch (Exception ex)
{
Debug.Print("Exception of type: " + ex.GetType().FullName);
Debug.Print(ex.Message);
if (onDownloadFinished != null) { onDownloadFinished(ex.Message); }
}
finally
{
// Close the response and streams objects here
// to make sure they're closed even if an exception
// is thrown at some point
if (response != null) response.Close();
if (remoteStream != null) remoteStream.Close();
if (localStream != null) localStream.Close();
}
// Return total bytes processed to caller.
return bytesProcessed;
}
}
}
so here are the questions:
1-why it downloads too slow?
2-why it stops downloading suddenly?
3-mp3 shield and fez connect shield uses the same spi module “SPI.SPI_module.SPI1” , will it makes a problem?