Skip to first unread message

Piero78

unread,
Jan 24, 2016, 10:21:14 AM1/24/16
to MIT App Inventor Forum
Hello! I've a TCP server programmed in Visual C#. I want to develop an app with MIT App Inventor 2 to comunicate to my server.
The code of the server is:
byte[] bytes = new Byte[1024]; // Buffer per contenere i dati in arrivo dal client

           
// Ottengo l'IP di rete LAN della macchina ed uso la porta 11000
           
IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
           
IPAddress ipLocale = ipHostInfo.AddressList[0];
           
IPEndPoint EPLocale = new IPEndPoint(ipLocale, 11000);

            textBox2
.Text = ipLocale.ToString();
           
           
// Configuro il socket TCP
            server
= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

           
try
           
{
               
// Imposto il server sull'endpoint locale ed attendo la richiesta del client
                server
.Bind(EPLocale);
                server
.Listen(10);

               
// Controllo se ci sono connessioni
               
while (true)
               
{

                   
Socket handler = server.Accept();

                    data
= null;

                   
// Una nuova connessione deve essere processata
                   
while (true)
                   
{

                        bytes
= new byte[1024];
                       
int bytesRec = handler.Receive(bytes);
                        data
+= Encoding.ASCII.GetString(bytes, 0, bytesRec);
                       
if (data.IndexOf("<EOF>") > -1)
                       
{
                           
break;
                       
}

                   
}
                   
                   
// Stampo i dati ricevuti dal client
                    data
= data.Replace("<EOF>", "");
                    textBox1
.Text = data;
                   
                   
// Invio la risposta al client
                    data
= "Dati ricevuti da " + ipLocale.ToString();
                   
byte[] risposta = Encoding.ASCII.GetBytes(data);
                    handler
.Send(risposta);
                   
                   
// Chiudo il socket
                    handler
.Shutdown(SocketShutdown.Both);
                    handler
.Close();
               
}
           
}
           
catch (Exception ex)
           
{
               
MessageBox.Show("Si è verificato un errore", "Errore", MessageBoxButtons.OK, MessageBoxIcon.Error);
           
}

My question is: Is there a way with MIT App Inventor 2 to communicate with the server?
Thanks.

Taifun

unread,
Jan 24, 2016, 10:36:25 AM1/24/16
to MIT App Inventor Forum
you could write your own extension...

more information about how to create an extension see here https://groups.google.com/d/msg/mitappinventortest/Ip2AX036d0U/5NJlAEbFCgAJ
however that will be more advanced and will require some Java skills...

Taifun

Trying to push the limits of App Inventor! Snippets, Tutorials and Extensions from Pura Vida Apps by Taifun. 

Piero78

unread,
Jan 24, 2016, 11:26:47 AM1/24/16
to MIT App Inventor Forum
Thanks for help! Do you know where can I find a list of extensions available at this time?
Thanks!

Taifun

unread,
Jan 24, 2016, 11:36:58 AM1/24/16
to MIT App Inventor Forum
as far as I know, there are currently the following extensions available
Taifun

Piero78

unread,
Jan 24, 2016, 1:05:37 PM1/24/16
to MIT App Inventor Forum
In your extensions there is one with WIFI functions, why you don't make methods to send and receive data?
Reply all
Reply to author
Forward
0 new messages