B4A Library [Moved] Socket.IO Client Library

Brandsum

Well-Known Member
Licensed User
Thanks @Brandsum. One thing I noticed, if i do the server emit with callback, then the event signature changes (it throw me an error at first), so I added a second object to the sub signature on B4A and it pass. When I checked the getType of the second signature object, it was a socketIOClient type, but the only method I could execute with no error on that socket was the disconnect method. So under that situation, I can see that the original library is receiveing the callback object.

Thanks for the update in advance.
FBP
Yup I noticed that too. Check v2.4. You can see the example of addEvent method on IDE though you can do like this,
B4X:
'If your server sends a callback function then the event signature will be

Sub eventname_open(message as object, ack as object)
  socket.sendAck(ack, array("your data"))
  log(message)
end sub

'If your server sends only data then the event signature will be
Sub eventname_open(message as object)
  log(message)
end sub
 

Carlos marin

Active Member
Licensed User
Longtime User
hello I have a concern, I have an app that uses post requests to be constantly communicating with the server. It has approximately 1000 users, would it be better to replace post requests for a socket connection with the node? Would not there be stability problems?
 

Brandsum

Well-Known Member
Licensed User
hello I have a concern, I have an app that uses post requests to be constantly communicating with the server. It has approximately 1000 users, would it be better to replace post requests for a socket connection with the node? Would not there be stability problems?
Post request to a node socket is much more stable than traditional post request. Lets say you are posting any data 10times in a minute, it will connect to server and disconnect from server 10times in a minute. But if you use socket then it will keep the connection open untill and unless the user is offline. And with socket.io lets say you are posting something to so domain and due to any issue it fails. So to send that again you have to write your own code. But here it will automatically retry untill it detects successful delivery. Like that there are too many advantages of using socket rather than post request.
 

Carlos marin

Active Member
Licensed User
Longtime User
Hi Brandsu, that information is very interesting, and the consumption of data by the mobile teams would be excessive, would not it?
and as for more than a thousand instantaneous connections, would it support node them?
 

Brandsum

Well-Known Member
Licensed User
Hi Brandsu, that information is very interesting, and the consumption of data by the mobile teams would be excessive, would not it?
and as for more than a thousand instantaneous connections, would it support node them?
Keeping a connection alive doesn't means transfering of data continuously. So mobile data will be consumed only if you transfer any data. And for checking new incoming messages it will consume a very little amount of data. facebook, whatsapp and all type of realtime messaging system use socket connection.
 
Last edited:

jtim3032

Member
Licensed User
Longtime User
The server I am connecting to uses the "query" parameter of the client connection options for authentication purposes. Would it be possible to add access to this parameter in the connectWithOptions method?

Thanks...
 

hears

Active Member
Licensed User
Longtime User
this lib only work with SDK 27 under,in SDK28 cannot work, you will get this error when connect :
io.socket.engineio.client.EngineIOException: xhr poll error
 

hears

Active Member
Licensed User
Longtime User
this lib only work with SDK 27 under,in SDK28 cannot work, you will get this error when connect :
io.socket.engineio.client.EngineIOException: xhr poll error
when SDK>27 ,pie by default only support https, so you need to add:

SetApplicationAttribute(android:usesCleartextTraffic, true)

inside the B4A Mainfest editer

if you use android studio project:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.mypackage.mylibrary">
<application android:usesCleartextTraffic="true" />
</manifest>
inside the application tag of AndroidManifest.xml

in order to use http in Android Pie
 
Last edited:
Top