I managed to create a C# Server that sends files to AS3(AIR) Clients using sockets
. On the AS3 side I'm using the flash.net.Socket
library to receive the data through TCP
.
This is how it works:
-> I turn on my server, and it listens for clients (plus I can create a list of connected devices);
-> I turn on my client and it automatically receives the data;
The trigger event to receive the data is made on the client, i.e., I simply turn the server ON and when the client turns ON, it gets the data, triggering these events:
socket.addEventListener(Event.CONNECT, onConnect); -> to connect to the server
socket.addEventListener(Event.SOCKET_DATA, onDataArrival); -> to receive the data
Now I want to do something different. I don't want to trigger it on the client, I want the server to do that, i.e, I want to turn on my client and on the server put in what client will get the data.
So why am I trying to make the client a client/server? Well, because my server is one machine, and my clients are XXX mobile devices that connect the server, and this is my approach to accomplish this.
So, given what I just said, I managed to create my AS3 client/server app that works just like I want it, using the flash.net.ServerSocket
library.
First I put the client listening:
serverSocket.bind(portNumber, "10.1.1.212");
serverSocket.addEventListener(ServerSocketConnectEvent.CONNECT, onConnectServer);
serverSocket.listen();
And then I receive the data using the flash.net.Socket
Event.SOCKET_DATA
And that's pretty much it. Works just like I want it to.
However, the flash.net.ServerSocket
is not compatible with mobile devices, yet...
So here's my problem: I need to send files from C# server (that needs to listen for clients so I can create a list of connected devices) to AS3(AIR) Clients, but I have to define which client is getting the data on the server, and the clients need to be prepared to receive that data anytime, therefore, listening, but there's a lot of them, that's why I consider them as clients.
And my question is: Is there a way to make a client listen for incoming connections and triggering an event when it happens, whithout using the Server Socket in AS3?
Also, if you have a different approach to accomplish my goal whithout using the C# server <-> AS3 client/server logic, please feel free to kick in your opinion.