Skip to first unread message
Assigned to taifu...@gmail.com by ghica.va...@gmail.com

Jean-Rodolphe Letertre

unread,
Jul 14, 2016, 6:28:40 AM7/14/16
to mitappinv...@googlegroups.com

Hello everybody,

Last year, I needed a component in AI2 that did the work of a client socket. As there wasn't any, I used Web component instead, but it didn't do everything I need. A few days ago, I saw that there were the possibility to use extensions, but didn't find a client socket one. I decided to make one so.

Here it is : ClientSocket extension V0.4.4.2 (Trailling 00 bug repair release) !

Properties :
- serverAddress (R/W)
- serverPort (R/W)
- hexaStringMode (R/W)
- connectionState (RO)
- debugMessages (RW)

Methods :
- Connect
- Disconnect
- SendData

Events :
- DataReceived
- RemoteConnectionClosed


Known bugs :
- I think that only messages less than 1024 bytes work
- If connection to server is lost (not server shutdown, but wifi connection problem by example), no events will indicate it (but crashes are now fixed :-) thx Axeley)
- on some android devices, disconnection of the serveur is not crashing anymore the app.

If you want to send non ascii data, modify hexaStringMode to true and send data as "303132" to send characters "012". Received data will be also hexa characters.

If you can, you can use it, test it and report me suggestions and bugs.

Cheers,

Jean-Rodolphe Letertre
ClientSocketAI2Ext.java
com.gmail.at.moicjarod.aix
TestSocket.aia

Ghica

unread,
Jul 14, 2016, 7:57:27 AM7/14/16
to MIT App Inventor Forum
It is really nice that you made this, although personally I am not quite sure what to do with it. Mabe you could add a description, or an example?

For us to use it though, you should provide it as an .aix file, that allows user to load it into their project.
I am sure it is described in the documentation how to create the .aix file: http://ai2.appinventor.mit.edu/reference/other/extensions.html
Cheers, Ghica.

Jean-Rodolphe Letertre

unread,
Jul 14, 2016, 8:11:10 AM7/14/16
to MIT App Inventor Forum
Hello,

aix file is given (the first file), but I have problems when I try to connect MIT AI2 companion, it says "no such class". I saw someswhere in the docs that there may be problems if I don't name the extension properly, maybe it is the reason why it's not working ?

The exemple of use ? The one I will do is a connection between an arduino and AI2, I will be able to contact the arduino from AI2, but now also, the arduino will be able to contact AI2 app (with Web component, AI2 app could only be the one which initiate communication, it asks and arduino reponds, with a socket, arduino can send information without being asked to by AI2 app). But it is only a very small part of what you can do with a client socket ...

Jean-Rodolphe Letertre

unread,
Jul 14, 2016, 8:13:13 AM7/14/16
to MIT App Inventor Forum
Another question : where do I have to put the icon I want to give to the extension ? I tried many path, but I always see brocken linked image for the icon.

Ghica

unread,
Jul 14, 2016, 8:16:20 AM7/14/16
to MIT App Inventor Forum
I expect Taifun knows the answer to your questions.
Cheers, Ghica.

Jean-Rodolphe Letertre

unread,
Jul 14, 2016, 12:00:39 PM7/14/16
to mitappinv...@googlegroups.com
New Version 0.2 :

- Better error message display
- aix file size reduced
- example app

Taifun

unread,
Jul 14, 2016, 12:12:11 PM7/14/16
to MIT App Inventor Forum
 I saw that there were the possibility to use extensions, but didn't find a client socket one. I decided to make one so.
great idea! thank you for your contribution!
as I can see, you found how to rename the package name meanwhile
concerning the icon, you have to use the default extension icon or provide the icon in the internet, see again the document chapter 4.2.1

example:

btw. for questions concerning working with the App Inventor or extensions, please use the Open Source Group in future https://groups.google.com/forum/#!forum/app-inventor-open-source-dev

Taifun

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


Jean-Rodolphe Letertre

unread,
Jul 14, 2016, 12:40:36 PM7/14/16
to MIT App Inventor Forum
Do you think I should open a new thread in this other Google Group to propose my work ?

Ghica

unread,
Jul 15, 2016, 6:26:38 AM7/15/16
to MIT App Inventor Forum
This is the right forum to show what you have made.
The developers forum would be the right place to ask questions when you have a problem creating your extension, but anyway, show there what you have done!
Cheers, Ghica.

Dave

unread,
Jul 15, 2016, 3:23:44 PM7/15/16
to MIT App Inventor Forum
I may have found a small bug that crashes app inventor companion.
The app crashes when I call the methode disconnect the whole app crashes.
It does not matter if I use the button click or remote connection close.

And another problem I found is that when you consecutive send data to fast it wil be send as a single line.
For instance if you send a number 2 and 5 it wil be send as 25. 

Jean-Rodolphe Letertre

unread,
Jul 17, 2016, 9:58:57 AM7/17/16
to MIT App Inventor Forum
Hello,

Thanks for your report,

I'm currently triing to solve the first problem (I think it's because of the closing of the socket while continuing reading the inputstream ...

Will watch for the second problem as soon as possible then.

Jean-Rodolphe Letertre

unread,
Jul 20, 2016, 9:00:38 AM7/20/16
to MIT App Inventor Forum
Ok, new version (0.3) that solves the disconnect problem (and also put an icon for the extension).

But I can't redo the second bug that send two data as a single line, can you give me the program you have done to produce this bug ?

Taifun

unread,
Aug 6, 2016, 10:23:45 AM8/6/16
to MIT App Inventor Forum
apk files are not allowed in this forum, see also the 
I removed it for you.
You might want to provide the aia file instead. Thank you.
Taifun

Jean-Rodolphe Letertre

unread,
Aug 11, 2016, 4:30:58 AM8/11/16
to MIT App Inventor Forum
Yes, that's right, I'll give aia file instead when I'll be releasing next version.

Jean-Rodolphe Letertre

unread,
Aug 11, 2016, 12:46:47 PM8/11/16
to mitappinv...@googlegroups.com
New Version : 0.4

Changelog :
- You are now able to send non ascii data, just modify the hexaStringMode to true and send "303132" to send characters 012. Received data will also be translated to an hexa string.

Cheers,

MoiCJarod

New Version : 0.4.1

Changelog :
- name of the extension changed to distinguish from Java library
- source file indentation reworked
- bug fixed :
    - extension was concatenating messages received. fixed
    - problem in detecting non hexa characters in hexa mode : fixed

Cheers,

MoiCJarod

Taifun

unread,
Mar 16, 2017, 7:12:47 PM3/16/17
to MIT App Inventor Forum
reopened

Artur Starz

unread,
Mar 17, 2017, 4:20:49 AM3/17/17
to MIT App Inventor Forum
Hi..

I tested this extension.. working with no problem when server is ok.. but..
1. when host in disabled (or connection lost etc. ) I have big  error (with "end application" button) 
"connection time out" and application crash.. "Connection error -
socket creation - falied to connect to xxx.xxx.xxx.xxx port yyyy"
should be any error handling (even enough indicator that the error
occurred or error number or error message )..
- I have screen1.erroroccurred enabled - unfortunately, does not assume these errors

Can I ask about adding such a feature so that the system does not communicate FAULTS?


2. Secont thing.. 
Connect Timeout - is very long - when server or network is unavailable i have message - "application is not responding. Close ?" - should only status change etc.

Best regards..

Artur





Alexey Brylevskiy

unread,
Mar 23, 2017, 4:50:54 PM3/23/17
to MIT App Inventor Forum
Hi,

Same here: crash on connection loss.
I connect to a Wifi AP (ESP8266) and open a connection using this extension and the example app. I'm able to exchange messages which is great, but as soon as the AP is turned off or goes out of wifi range, the app crashes.

Thank you Jean-Rodolphe for your hard work, and can you please fix this issue?

Thanks,
Alexey

Jean-Rodolphe Letertre

unread,
Mar 24, 2017, 8:47:29 AM3/24/17
to MIT App Inventor Forum
Hello Artur,

Thanks for your report, I have been able to reproduce the first problem you described problem and I am actually triing to solve it. It must be a kind of exception that i don't raise, but I can't find which ...

For the second problem, the timeout for a connection that doesn't work is 5 seconds, it's odd that it says "application not responding" ... is it before 5 seconds ?

Cheers,

Jean-Rodolphe

Jean-Rodolphe Letertre

unread,
Mar 24, 2017, 8:50:25 AM3/24/17
to MIT App Inventor Forum
Hello Alexey,

Yes, the problem must be the same as Artur, I am currently triing to solve it but not with success for now ... And the compilation and a new try when I make changes is very long ... Will continue to try and as it is easily reproducable, when I will find a workaround, will post here a new version.

Cheers,

Jean-Rodolphe

2009marius15

unread,
Mar 25, 2017, 11:07:19 AM3/25/17
to MIT App Inventor Forum
Hello Jean-Rodolphe,

it's possible for you to make an UDP client to send/receive data with UDP?
Also join/dejoing multicast and broadcast adresses?!

That would be very great! There are a lot of guys that would need them!

TimAI2

unread,
Oct 19, 2018, 5:50:03 AM10/19/18
to MIT App Inventor Forum
Reopened

Fernando Muñoz

unread,
Oct 19, 2018, 5:57:42 AM10/19/18
to MIT App Inventor Forum
Thanks Tim
Hi

i'm using the extension but when i try to disconnect i have a crash of the application. Just a connection and a disconnection and the application crash.

do you know if someone has had the same problem?

Regards

Jean-Rodolphe Letertre

unread,
Oct 20, 2018, 2:10:19 AM10/20/18
to MIT App Inventor Forum
Hello Fernando,

I'm aware of this problem, but it seem not to appear on every model of smartphone. As it does not appear on mine, it's a bit difficult to solve it :-(

I studied my code and don't find anything that could provoque this error (as you say, just a connection and a disconnection).

Fernando Muñoz

unread,
Oct 22, 2018, 11:45:42 AM10/22/18
to MIT App Inventor Forum
Yes Jean Rodolphe, in my phone it doesn't work (Samsung J5) but in other models it works. I know it is dificult to reproduce it but if you can do it, please send me a message.
Many thanks

Fernando Muñoz

unread,
Oct 22, 2018, 11:49:13 AM10/22/18
to MIT App Inventor Forum
Jean Rodolphe, maybe you could stop to read data in TCP socket before to disconnect. Or developping an action to stop the reception data

Jean-Rodolphe Letertre

unread,
Oct 23, 2018, 4:02:48 AM10/23/18
to MIT App Inventor Forum
I will try to find some time to test this. Will I be able to count on you to test the aix with your phone ?

Fernando Muñoz

unread,
Oct 23, 2018, 4:37:27 AM10/23/18
to MIT App Inventor Forum
Thanks Jean Rodolphe

Fernando Muñoz

unread,
Oct 23, 2018, 10:17:26 AM10/23/18
to MIT App Inventor Forum
Of course Jean, you can send me aix file

Hari Momchilov

unread,
Oct 24, 2018, 9:10:46 AM10/24/18
to MIT App Inventor Forum
Hello ! I have a problem ! I can't download the files ... it gives me error 404 ! Please help me !

Ghica

unread,
Oct 24, 2018, 11:04:54 AM10/24/18
to MIT App Inventor Forum
Hari,
I think you are breaking in on another forum thread.
If you have a question, start a new thread and describe what you cannot download. From your message we cannot know.
Cheers, Ghica.

Fernando Muñoz

unread,
Oct 25, 2018, 5:20:29 AM10/25/18
to MIT App Inventor Forum
Hi Jean Rodolphe
i'm trying to do backups connection. It's means when the first tcp connection is refused i want to connect to a second server. The problem is when the connection is refused the program doesn't continue to execute. A simple example is:
when connectionstate = false
set textxbox to NOT CONNECTED

It doesn't work

Many thans

Jean-Rodolphe Letertre

unread,
Oct 25, 2018, 6:34:52 AM10/25/18
to MIT App Inventor Forum
It's not the way I thought it to work ... It's because, when the app can not connect to server, it is sending an exception, and then stopping the actual thread.

Anyway, here is a workaround with three clock objects that is likely to fit your need :


The three clock are initialised with TimerAlwaysFire and TimerEnabled properties disabled. Time is set to 100 for Clock1 and 5000 for Clock2 and Clock3 (I put a 5s timeout for connecting to server. Your first server should be configured directly in the designer, and the second one in the "When Clock2.timer" block event (192.168.0.87:10001 mentioned above).

And as a workaround within my extension, I could add a property that deactivate the throwing of exceptions when a problem occur ... But it needs more time and tests ... And this may break some of my code ... So, it will be for future ;-)

Fernando Muñoz

unread,
Oct 26, 2018, 3:56:17 AM10/26/18
to MIT App Inventor Forum
Thanks Jean

when you want i can test the version

Regards
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Fernando Muñoz

unread,
Oct 26, 2018, 4:30:42 AM10/26/18
to MIT App Inventor Forum
Hello Jean
i have tried your option but when i receive a TCP-RESET the application crashe. I attach the aia file
Regards and thanks
Message has been deleted
Message has been deleted

Fernando Muñoz

unread,
Oct 26, 2018, 4:32:44 AM10/26/18
to MIT App Inventor Forum
I can't attach a file. Basically is you picture
Thanks

Ghica

unread,
Oct 26, 2018, 4:48:48 AM10/26/18
to MIT App Inventor Forum
To attach a .aia with an extension, you could put the .aia on a google drive, share it, and provide a link to it here on the forum.
Cheers, Ghica

Fernando Muñoz

unread,
Oct 30, 2018, 4:35:11 AM10/30/18
to MIT App Inventor Forum
Hi Jean

just to know (i have my project stopped) if you are changing something in the extension to resolve the disconnection chash.

Thanks a lot

Jean-Rodolphe Letertre

unread,
Oct 30, 2018, 5:23:59 AM10/30/18
to MIT App Inventor Forum
As I hove no idea of the line causing the problem, it's difficult to change anything.

Can you do an "adb logcat" on a computer where android tools are installed, usb connect your android phone to it, process the deconnexion error and send me what logcat show me ?

Help on how adb logcat can be used is here : https://developer.android.com/studio/command-line/logcat

Fernando Muñoz

unread,
Oct 30, 2018, 5:41:24 AM10/30/18
to MIT App Inventor Forum
Ok i will do it
Thanks

Fernando Muñoz

unread,
Oct 30, 2018, 10:34:20 AM10/30/18