Using socket on android/iOS


I’m trying to use the class but having problems on Android. Things work fine on flash. Is there anything different that i have to do for android? I’m currently just creating ByteArrays and using Socket writeBytes method and listening for ProgressEvent.SOCKET_DATA for data on the socket.


Hello mpgdev,
you’ll have to use instead.

Hmmm, looking at the api for i’m wondering how i can send and receive binary data.

Is there an example somewhere?


I’m pretty sure that the OpenFL socket class uses under the hood, perhaps someone could take a look if things are not behaving quite as expected

The problem might be the creation of the bytearray. It looks like whenever i write something to it using writeByte that value appears to be 0, so in the end the bytearray is full of 0’s. Again not sure why this doesn’t work since it works for the flash target.

indeed it does use sys under the hood since . My bad :slight_smile:
mpgdev, if you had a sample of what you were doing, maybe that would help.

Well, it isn’t too complicated. I create a
add listener for Event.CONNECT, ProgressEvent.SOCKET_DATA, and the errors.

I then call socket.connect(host, port). It connects, since my eventlistener is called.

I then get some data from the host which i them try to send some values to the host. This is where it fails.

I create an openfl.utils.ByteArray like so var byteArr:ByteArray = new ByteArray(); Then i start writing to it like so byteArr.writeByte(0xFF); etc… with other values.

Finally i call socket.writeBytes(byteArr) and socket.flush().

That is all that i’m trying to do. When i print out the values of the bytearray they are all 0. So i think think the problem is in the bytearray possible.

Using openfl 3.0.3
haxe 3.1.3
lime 2.3.3

So it looks like it isn’t a socket problem.

Things get stuck in a while loop which blocks any other operations including network io.