Trasmission via socket very slow while display is connected on fez spider II

Hi to everyone I’m making a project for university with a fez spider II and I need to send the photo taken with fez to my pc.I do that via socket programming.
The transmission (about 250kb) lasts about 1 second.
After realizing the graphic interface on the display, the transmission slowed drastically.The fez occasionally send and trasmission lasts even 200, 300 seconds.
After so many tests I realized that disconnecting, on visual studio, the display, the transmission returns to be “fast”.
It is enough connect the display in visual studio, even without actually using it, to make the transmission slow.
I think it is a problem of lack of computing power to handle both the display and the socket transfer.
The professor backs my thesis thinking that there is an ever-running thread that handle the display that removes CPUs and advised me to try to disable that thread during the trasmission, advising me to look at the source code of the display drivers, which I honestly did not found yet.
I have to use the display.
Can anyone help me? How I can solve the problem?

1 Like

Welcome to the forum.

I’d doubt that the screen alone is causing your problem, but lets not discount anything.

Can you confirm you’ve checked the firmware version on the device and your install match? Run FezConfig and capture a screenshot of the check and post it back here

Can you share with us how you created the project (what VS version, what project template you used, including whether it was Gadgeteer or not, and what framework version you may have chosen), and most importantly we need a small demonstration project that we can use to reproduce this - so a minimum of your own code but something that can show the behaviour. Also, have you looked at a network capture of the traffic to see what the sequencing looks like, are there large gaps in packet transmission for example, or are there lots of retransmits?

Also can you please let us know if you’ve looked for other threads that relate similar issues and how they may have been solved?

@ anto1192 - What display? What kind of processing are you doing to update the display?

Hi, I loaded the screenshot on FEZ Config. I don’t know if it is what you asked to me.
About the project, I used Visual Studio 2015, template Visual C# - Windows - Gadgeteer, .NET Micro Framework 4.3
About the code, this is the method I use on the FEZ to transmitt picture and other things:


private String usaSocket(String allergia)
        {
            IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("192.168.1.72"), 1501);
            Socket clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            try
            {
                clientSocket.Connect(ipep);
                Debug.Print("Socket connected to " + clientSocket.RemoteEndPoint.ToString());
                Stream s = new NetworkStream(clientSocket);
                StreamReader sr = new StreamReader(s);
                StreamWriter sw = new StreamWriter(s);

                sw.Flush();

                int sent = SendVarData(clientSocket, foto);
                if (sent == -1)
                {
                    Debug.Print("Error sending the file");
                    clientSocket.Close();
                    return "Error sending the file";
                    
                }

                Debug.Print("Picture send: byte -> " + sent);
                
                
                sw.Flush();
                sw.WriteLine(allergia);
                sw.Flush();

                String messaggioRicevuto = sr.ReadLine();
                Debug.Print("Message received: '" + messaggioRicevuto + "'");
                if (messaggioRicevuto == null)
                {
                    //non dovremmo mai essere qui
                    Debug.Print("No response received");
                    clientSocket.Close();
                    return "No response received";
                }
                string[] words = messaggioRicevuto.Split(',');
                Risultato r = creaRisultato(words);
                String risultati = stampaRisultati(r);

                clientSocket.Close();
                Debug.Print("Socket closed");
                return risultati;
            }
            catch (SocketException se)
            {
                Debug.Print("SocketException : " + se.ToString());
                clientSocket.Close();
                return "Error, try again";
            }
        }
private int SendVarData(Socket s, byte[] data)
        {
            int total = 0;
            int size = data.Length;
            int dataleft = size;
            int sent;

            byte[] datasize = new byte[4];
            /*for (int i = 0; i < 4; i++)
            {
                datasize[i] = (byte)(data.Length >> (i * 8) & 0xff);
            }*/
            datasize = BitConverter.GetBytes(size);
            sent = s.Send(datasize);
            Debug.Print("size " + size);
            try {
                total = s.Send(data, size, SocketFlags.None);
                //total = s.Send(Bitmaps.ConvertToFile(bt), 230454, 0);
            } catch (Exception e)
            {
                return -1;
            }
            /*while (total < size)
            {
                try
                {
                    sent = s.Send(data, total, dataleft, SocketFlags.None);
                }
                catch (Exception e)
                {
                    Debug.Print("Error sending the file");
                    return -1;
                }

                total += sent;
                dataleft -= sent;
            }*/
            /*
            for (int i = 0; i < size; i++)
            {
                try { 
                sent = s.Send(data,i,1, SocketFlags.None);
                }
                catch (Exception e)
                {
                    Debug.Print("Error sending the file");
                    return -1;
                }
                total += sent;
            }*/
            return total;
        }

The second method is only to trasmitt the photo. As you can see there are some comments. I try all the possibilities you can see.
The byte[] data contains the photo. I capture the picture through a proximity sensor. Then I have this code:


void camera_PictureCaptured(Camera sender, GT.Picture picture)
        {
            Debug.Print("Picture captured");
            bt = picture.MakeBitmap();
            Debug.Print("Width: " + bt.Width + " Height: " + bt.Height);
            foto = new byte[bt.Width * bt.Height * 3 + 54];
            Bitmaps.ConvertToFile(bt, foto);

            String risultato = "";
            if (collegato)
            {
                try
                {
                    
                    risultato = usaSocket(allergia);
                }
                catch (Exception e)
                {
                    risultato = "Network error";
                    Debug.Print("Network error");
                }
            }
            else
            {
                risultato = "Network not available";
                Debug.Print("Network not available");
            }


            /*textRisultato.Text = risultato;
            window.FillRect(textRisultato.Rect);
            Glide.MainWindow = window;*/
            ciclo();

        }

The server is written in Java language. This is the code to receive the photo:


private static void riceviFile(Socket socket) throws Exception{
        InputStream is = socket.getInputStream();
        File file = new File("download.jpg");
        FileOutputStream fos = new FileOutputStream(file, false);
       
        System.out.println("Receiving file...");
        byte[] dim = new byte[4];
        is.read(dim);
        int dimensione = convertByteToInt(dim);
        System.out.println("--Dimension: " + dimensione + " byte");       
        long inizioDownload = Calendar.getInstance().getTimeInMillis();
        
        
        //METODO VELOCE -> NON FUNZIONA CON FEZ
        //byte[] buf = new byte[dimensione];
        //is.read(buf);
        //fos.write(buf,0,dimensione);
        //---------------------------------------
        
        //METODO LENTO
        int read;
        int cont = 0;
        byte[] buf = new byte[1];
        for (int i =0; i < dimensione; i++){
            read = is.read(buf);
            if (read == -1){
                throw new Exception("Error downloading");
            }
            //System.out.println(cont + " ");
            if ((cont % 1024) == 0){
                System.out.println(cont/1024 + " kb");
            }
            fos.write(buf, 0, read);
            cont+=read;
        }
        //-------------------------------
        
        long fineDownload = Calendar.getInstance().getTimeInMillis();
        long durataDownload = fineDownload - inizioDownload;
        double scaricamento = (double)dimensione/durataDownload;
        
        System.out.println("--Download finished\n--duration: " + durataDownload + "ms\n--Average download speed: " + scaricamento + " kb/s");
        fos.close();          
    }

First of all, I’m sorry but there are some things in italian language.
I set on the server a timeout of 5 seconds; with this code, the server doesn’t generate an error.
This method

byte[] buf = new byte[dimensione];
is.read(buf);
fos.write(buf,0,dimensione);

is faster to receive; I don’t remember so well what it happen but I remember that doesn’t work with the FEZ.
Probably I receive only a part of the photo.

Anyway, if I connect the display on the FEZ, TimeoutException is generated.

The display is the “Display TE35”.
I analyzed the traffic and seems that there are many retransmissions.
Finally, I did not find this issues in other threads.