G120 and ENC28 - max speed using TCP

I am using the G120 module with ENC28 Ethernet module. I would like to use it for the file transfer during TCP protocol. Now I have maximum speed about 30 - 40 kB/s. I am using HTTP request and the PUT method.

Thanks for the answer


Hi Andre,
thanks, my code is here:

  while (eth.NetworkInterface.IPAddress == "")
                Debug.Print("Awaiting IP Address");

            Debug.Print("IP Address Granted: " + eth.NetworkInterface.IPAddress);
            IPAdressReady = true;

            int Number = 0;
            long PutLength, ActLength;
            string FileName = "";
            byte[] buffer = new byte[50 * 1024];
            int NumberCycles, ActCycle;

            HttpListener listener = new HttpListener("http", 1080);

            while (true)
                HttpListenerResponse response = null;
                HttpListenerContext context = null;
                    context = listener.GetContext();
                    response = context.Response;

                    switch (context.Request.HttpMethod)
                        case "GET":
                            response.StatusCode = (int)HttpStatusCode.OK;
                            byte[] HTML = Encoding.UTF8.GetBytes(
                            "<html><head><title>.NET Micro Framework Web Server</title></head>" +
                            "<body><bold>Number of connection: " + Number.ToString() + ".</bold></body></html>");
                            response.ContentType = "text/html";
                            response.OutputStream.Write(HTML, 0, HTML.Length);

                        case "PUT":
                            PutLength = context.Request.ContentLength64;
                            NumberCycles = (int)(PutLength / (long)buffer.Length);
                            ActCycle = 0;
                            ActLength = 0;
                            FileName = "Test" + Number.ToString() + ".txt";
                            Stream InputStream = context.Request.InputStream;
                            SDWriteStream = new FileStream(VolumeInfo.GetVolumes()[0].RootDirectory + @ "\" + FileName, FileMode.Append);

                            while (ActCycle < NumberCycles)
                                if ((NumberCycles - ActCycle) == 1)
                                    InputStream.Read(buffer, 0, (int)(PutLength - ActLength));
                                    SDWriteStream.Write(buffer, 0, (int)(PutLength - ActLength));
                                    ActLength = ActLength + (long)buffer.Length;
                                    InputStream.Read(buffer, 0, buffer.Length);
                                    SDWriteStream.Write(buffer, 0, buffer.Length);
                                    ActLength = ActLength + (long)buffer.Length;

                            SDWriteStream = null;
                            sdPS = null;



                catch (Exception)

You may be able to speed up your SPI interface … how did you open the SPI?
the last parameter is the SPI speed, so try to increase that if it is too low (the default is 4000kHz). i.e.: Eth1 = new EthernetENC28J60(SPI.SPI_module.SPI2, Pin.P1_17, Pin.P0_5, Pin.P1_14, 10000);

Hi Lurch,
yes, I tried to change this value up to 20000, but I didn’t see the difference in the file transfer speed.
From my point of view there is a hardware limitation - this is a question for the GHI.


I am not sure if we checked speed but my guess this should be about 50K. We will look into this in near future to see how we can improve performance.

Hi Gus,
thank you for the answer.


And I have a question.

The new module G400 will be faster? For me is no problem to use it.


theoretically, at 4000Kb you can reach up to few hundred KB/s. So don’t need to change that value too high to get stable.

@ Thomas_H -

I didnt work with the HTTP listener Class yet, but I have some questions to your code.

Is it usual and efficient to use such a large buffer size of 50k ?
Are you sure, that your:

InputStream.Read(buffer, 0, buffer.Length);

always returns with the buffer completely filled?

Is it not more save to get the return value from the InputStream.Read method and calculate the filesize from the return values?

Regards Roland

We will do some benchmarking on all devices and share when available.

1 Like

@ RoSchmi

I tried a few buffer sizes. The first choise was the buffer size 8kB = RAM size of ENC28. This method returns the buffer completly filled.

I didn’t have a problem with the file. It was completly transferred to the SD card.

Are you sure you only measure the Ethernet speed and not the overall speed including writing to SD card?

Hi RobvanSchelven,
yes, this speed is for the all file transfer. I tried to use print on the console the actual time and the most critical line is

InputStream.Read(buffer, 0, buffer.Length);

where the reading time is about a few seconds. The SD writing is fast.

Thanks for the respone


P.S. I bought G400 module from Mouser and I will try to use it.

@ Thomas_H

did you ensure, that it is not a matter of the data sender or a slow network component that makes the transmission slow?
What is the size of the files you want to send?

Hi RoSchmi,
I tried the 850kB file and 3.5MBfile.

It was pear-to-pear connection using Win7. I programmed my own application in VS on the notebook site. (static IP)

I also tried the transfer using Mac OS X (IP adress from DHCP).

The speed was the same (30 - 50kB/sec)

I would like to transfer the files about 100MB - the good file transfer speed is about 500kB/sec.

@ Thomas_H -
I think, that if the command
InputStream.Read(buffer, 0, buffer.Length);
is blocking for such a long time, the reason cannot be that your mainboard is to slow. The reason must lay in the ENC28 Module (cant believe that the module is so slow) or in the incoming data rate (Wire shark analysis ?). What do you mean with files about 100MB, filesize or transfer speed 100 MB/sec? Which transfer time did you measure for the 850kByte and 3,5 MByte files?