Hi again. This is a new and difficult topic for me that I’m attempting. I am using AIR 2 .0 beta’s API to create a server and client. Far as I know client is similar to a regular client before the new API .
Does anyone have experience in working with the socket class? I can send a string to my server and have it send it back, thats great. But I’d like to send other information, such as a variable containing the username(chat application) and then another containing the variable. And access each in the server. Is it possible to send an array?
Client:responseSocket.writeUTFBytes(string) responseSocket.flush()Server:
//socket is stored in the array 'sockets' when it connects, this code is when data has been sent to the server afterward
var socket:Socket = e.target as Socket
var bytes:ByteArray = new ByteArray()
socket.readBytes(bytes)
//I have no idea why "" is placed at the start of the string? Taken from a code excerpt on the web
var message:String = "" + bytes
//Sends message to all connected Clients
for(var i:int = 0; i < sockets.length; i++) {
sockets[i].writeUTFBytes(message)
sockets[i].flush()
}
At a later point I’ll need to send alot more information, I’d be storing the information inside class instances. Is it possible to send an entire class over from one client to the server to update the information of that instance on the other client?
I think I could send a string sort of like a url string with the ‘var=value&var2=value2’ and then split the string up into an array? I’m sure theres a better way then that though right?
Any help appreciated, theres some wicked developers here :]
Was more of a bytes array issue:
http://livedocs.adobe.com/flex/3/html/help.html?content=ByteArrays_2.html
I couldn’t figure out how to read the byte array into an array on the server side as the example only gives me a way to write the array into bytes. Further down though, is an example of write/read object(). I can use this and it works well, I have’nt tried but think I can use this for sending/updating class instances too :]
Does anyone have a good resource for learning and understanding byte arrays and sockets better? Preferably as3 oriented.
