Are "openfl socket" and "as3 socket" the same?

Hello everyone, may I ask if “openfl socket server-side socket” and “as3” are the same? Are there any different behaviors?

On native targets, openfl.net.Socket and openfl.net.ServerSocket should be the same as flash.net.Socket and flash.net.ServerSocket. If you encounter differences, you should report a bug.

On HTML5, openfl.net.Socket uses a web socket instead because web browsers don’t expose raw sockets to JavaScript. ServerSocket is not available on HTML5.

1 Like

Does’ native platform ‘mean’ air '?

Hello, I would like to know if “openfl socket server socket” behaves the same as “as3 socket server socket” on “Windows exe” and native Android targets, and if there are any differences

What about UDP? Thank you

In this context, yes it would.

  • OpenFL sys targets all use raw TCP sockets when you implement openfl.net.Socket.
  • The air target also makes use of raw TCP sockets, as that will ultimately become flash.net.Socket.

These are just raw TCP sockets with no protocol or protocol based connection handling. It sends and receives binary data you’ll need to structure in some way that’s meaningful and should work when communicating with any framework also making use of raw TCP sockets, provided you can correctly parse the binary data at each end.

Let me add that I would like to know if the behavior of “socket, server-side socket, DatagramSocket” in “openfl” is the same as that of “socket, server-side socket, DatagramSocket” in “as3” on native Android systems, “Windows exe” and “HTML5”? Can you tell me if there are any differences? Thank you

It is a raw Datagram (UDP) socket, and in that respect, the same. There is no higher level AIR specific protocol for example that you’ll need to cater to.

The key condition is that each end of the connection is able to successfully parse the binary data you send over it.

@Bink

Do you often use ‘socket’ as well? Are you sending bytes directly or sending ‘json’?

I write the data into an ‘object’ and then convert it to ‘json’ to send the entire ‘json’

Yes I have often used the Socket class in projects. I’ve also used it in the form of WebSocket when targeting HTML.

You can convert JSON to Bytes, and back again, so that’s not a bad way to do it. JSON can be fairly inefficient size wise though, so in more recent projects I’ve switched to MessagePack. I’m using this currently in a production environment to send and receive data from a cloud based Node.js server.

1 Like

OpenFL’s “native” targets are Neko, HashLink, and C++ (windows, mac, linux, android, and ios). Native targets load either lime.ndll or lime.hdll, which includes code compiled from C++ that may be called from Haxe.

2 Likes