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
to MIT App Inventor Forum
Hi Jean
here the log
Regards
Logcat.txt

Jean-Rodolphe Letertre

unread,
Oct 31, 2018, 4:26:41 AM10/31/18
to MIT App Inventor Forum
Hello,
Can you tell me if you makes the application crashing in the same way when you try to connect twice to an existing server (or if it only tells "Connect error, socket connected yet, please disconnect before reconnect !" in a popup).
Jean-Rodolphe

Fernando Muñoz

unread,
Oct 31, 2018, 5:29:15 AM10/31/18
to MIT App Inventor Forum
Hi

i have installed the app TestSocket, i have made a connection TCP, the socket was etablished and i push the disconnect button. In the log i have tried to take only the disconnection log
Thanks

Fernando Muñoz

unread,
Oct 31, 2018, 6:32:59 AM10/31/18
to MIT App Inventor Forum
Hi

here the log from a direct disconnection. I try to open a socket but server sends a TCP-RESET

Thanks
TCPLog_direct_disconnection.txt

Fernando Muñoz

unread,
Nov 5, 2018, 4:04:37 AM11/5/18
to MIT App Inventor Forum
Hi Jean
have you been able to see something?
Thanks

GA

unread,
Jul 24, 2019, 2:28:29 AM7/24/19
to MIT App Inventor Forum
Hello,

I have been trying to send tcp data with your program on mit ai2.
First off all thank you.

When i send data such as     "1\ff\00\00\00\00\f0\0f/"
server receives data as         "1\\ff\\00\\00\\00\\00\\f0\\0f/"

If I'm not wrong received data should look like "1\xff\x00\x00\x00\x00\xf0\x0f/"

how can i correct this?

regards

Jean-Rodolphe Letertre

unread,
Jul 24, 2019, 4:47:50 AM7/24/19
to mitappinv...@googlegroups.com
Hello,

I don't understand what you want to send :

- "1\ff\00\00\00\00\f0\0f/" as ASCII
or
- bytes 01, FF, 00, 00, 00, 00, F0, 0F
or something else ?

Why should 'x' appear on received data ?

Jean-Rodolphe

GA

unread,
Jul 24, 2019, 7:24:57 AM7/24/19
to MIT App Inventor Forum
Hello,
as ascii if its possible and with out any changes.
thanks

Jean-Rodolphe Letertre

unread,
Jul 24, 2019, 8:34:15 AM7/24/19
to MIT App Inventor Forum
And what about the x that appear in the string when you talk about the data you should receive :

GA

unread,
Jul 24, 2019, 10:19:09 AM7/24/19
to MIT App Inventor Forum
Well i can add to original data by hand

GA

unread,
Jul 24, 2019, 11:39:29 AM7/24/19
to mitappinv...@googlegroups.com
Hello again,

all in ascii
 
my first data is like        "31 ff 00 00 00 00 f0 0f 2f"
i have converted it to    "1\ff\00\00\00\00\f0\0f/"

working TCP data is     "1\xff\x00\x00\x00\x00\xf0\x0f/" (which i'm sending it from PC with 'Packet Sender' as "31 ff 00 00 00 00 f0 0f 2f")

When i send my data    "1\ff\00\00\00\00\f0\0f/" with your extension server receive it like "1\xff\x00\x00\x00\x00\xf0\x0f/"

also i have tried to sent "1\xff\x00\x00\x00\x00\xf0\x0f/" with your extension, result is "1\\xff\\x00\\x00\\x00\\x00\\xf0\\x0f/"

Jean-Rodolphe Letertre

unread,
Jul 25, 2019, 4:05:46 AM7/25/19
to mitappinv...@googlegroups.com
I think that in that case you should use HexaString mode :

Put HexaStringMode property to true, then send directly string "31FF00000000F00F2F", my extension will convert the string to hexa values in it and sending it to server.

Tell me if it works better.

GA

unread,
Jul 25, 2019, 12:19:23 PM7/25/19
to mitappinv...@googlegroups.com
Well thank you. why i haven't tried it before i don't know. my mistake...

I have sent "31ff00000000f00f2f" in Hexa mode.

server received "1\xff\x00\x00\x00\x00\xf0\x0f/\x00" so it didn't work (for server to work bold part should not be there).

for server to work received data should be "1\xff\x00\x00\x00\x00\xf0\x0f/"

best regards
GA

Jean-Rodolphe Letertre

unread,
Jul 25, 2019, 12:24:24 PM7/25/19
to MIT App Inventor Forum
ok, trailing 00 seems to be a bug. I have To modify the extension code. I send you a mail When new version is uploaded.

GA

unread,
Jul 25, 2019, 12:28:48 PM7/25/19
to MIT App Inventor Forum
Thank you very much. I will be waiting
GA

GA

unread,
Jul 26, 2019, 12:32:01 AM7/26/19
to MIT App Inventor Forum
Hello,
This updated version works fine.
Thank you very much.
GA

GA

unread,
Aug 2, 2019, 2:12:52 AM8/2/19
to mitappinv...@googlegroups.com
Hello,

Now i am using your extension with mit Ai2.
I'm try to disconnect and connect to another server.

But when i give disconnect command. App crashes.

Or after 5000 ms of connection app crashes!

How can i prevent these?

Thank you

Juan A. Sanchez Cañestro

unread,
Oct 30, 2019, 4:03:56 PM10/30/19
to MIT App Inventor Forum
Hi! Same problem here. When I disconnect, the App closes :-(

Any ideas?
Thank you

Taifun

unread,
Oct 30, 2019, 4:10:06 PM10/30/19
to MIT App Inventor Forum
to help the developer of the extension to fix that issue, you could post a Logcat output, see also https://community.appybuilder.com/t/capturing-device-logs-using-adb/83?u=taifun

Taifun

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

Juan A. Sanchez Cañestro

unread,
Nov 2, 2019, 7:40:56 PM11/2/19
to mitappinv...@googlegroups.com
Hi! I have just repeated the "disconnection and app crash". This is the ADB snippet:

11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext: ERROR_READ
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext: java.net.SocketException: Socket closed
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext:    at java.net.SocketInputStream.read(SocketInputStream.java:186)
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext:    at java.net.SocketInputStream.read(SocketInputStream.java:120)
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext:    at java.net.SocketInputStream.read(SocketInputStream.java:106)
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext:    at com.gmail.at.moicjarod.ClientSocketAI2Ext$1.run(ClientSocketAI2Ext.java:193)
11-02 23:38:39.971  3824  6908 E ClientSocketAI2Ext:    at java.lang.Thread.run(Thread.java:762)
--------- beginning of crash
11-02 23:38:39.978  3824  6908 E AndroidRuntime: FATAL EXCEPTION: Thread-40
11-02 23:38:39.978  3824  6908 E AndroidRuntime: Process: appinventor.ai_jacanestro.Mando_LG_Serial, PID: 3824
11-02 23:38:39.978  3824  6908 E AndroidRuntime: com.google.appinventor.components.runtime.errors.YailRuntimeError: Connect error (read)Socket closed
11-02 23:38:39.978  3824  6908 E AndroidRuntime:        at com.gmail.at.moicjarod.ClientSocketAI2Ext$1.run(ClientSocketAI2Ext.java:269)
11-02 23:38:39.978  3824  6908 E AndroidRuntime:        at java.lang.Thread.run(Thread.java:762)
11-02 23:38:39.979  3824  3824 D ViewRootImpl@aef5b58[Screen1]: ViewPostImeInputStage processKey 1
11-02 23:38:40.070  3824  3824 D ViewRootImpl@aef5b58[Screen1]: MSG_WINDOW_FOCUS_CHANGED 0
11-02 23:38:40.093  3824  3824 I Form    : Form Screen1 got onPause
11-02 23:38:40.355  3824  3824 D ViewRootImpl@aef5b58[Screen1]: mHardwareRenderer.destroy()#1
11-02 23:38:40.403  3824  3824 D ViewRootImpl@aef5b58[Screen1]: Relayout returned: oldFrame=[0,0][720,1280] newFrame=[0,0][720,1280] result=0x5 surface={isValid=false 0} surfaceGenerationChanged=true
11-02 23:38:40.720  3824  3824 I Form    : Form Screen1 got onStop
11-02 23:38:40.720  3824  3824 I Form    : Form Screen1 got onDestroy
11-02 23:38:40.745  3824  3824 D ViewRootImpl@aef5b58[Screen1]: mHardwareRenderer.destroy()#4
11-02 23:38:40.745  3824  3824 D ViewRootImpl@aef5b58[Screen1]: dispatchDetachedFromWindow
11-02 23:38:40.758  3824  3824 D InputTransport: Input channel destroyed: fd=60 

Hope it helps to find the bug

andre castro

unread,
Nov 5, 2019, 8:30:35 AM11/5/19
to MIT App Inventor Forum
Did you try disabling debug messages? By default it is enabled.
It was one of the last changes on this Extension, supposed to avoid this error.

Vladimir

unread,
Jan 5, 2020, 11:14:38 AM1/5/20
to MIT App Inventor Forum
Good day!
Nobody fixed the problem with reconnection?
Reply all
Reply to author
Forward
0 new messages