View Full Version : Socket/XMLSocket class. Which to choose.
OmniNL
December 4th, 2009, 06:39 AM
Hi,
Ive been trying to use the Socket class for a while now but when i search for any tutorials i get more pages that review the XMLSocket class. What's the difference? And which one should i use for realtime multiplayer games?
So far i already got a server/client written with the Socket class but it's given me some trouble reading/editing the binary data in Java. Because it's in AMF format.
Should i use XMLSocket?
Thanks
wvxvw
December 4th, 2009, 07:29 AM
Go with Socket IMO. There is opensource Java implementations of AMF, in GraniteDS if I'm not mistaken... However, I think that with some effort you may come up with your own, it's not really difficult. Usually you'd want the max performance out of socket, if you already go for that option, so, definitely binary socket would be faster - less data to send.
Besides, AMF has IExternalizable option, which basically means that all that you will be using from AMF is the header and objects IDs, the content may be whatever you want - thus allowing for your own encoding / decoding techniques to be used.
Also remember to implement the class-mapping if you're sending typed objects, this will lower expenses, as you'll have to send the type description only once per connection.
You probably are finding more info on XMLSocket simply because it also exists in AS2, thus, has larger user base.
PS. Ultimately, you could use your own encoding (i.e. either write your own, or use some other existing technique, like Protobuf (http://code.google.com/p/protobuf/), that is if for whatever reason you don't like AMF).
OmniNL
December 4th, 2009, 08:54 AM
Thanks for your response wvxvw, ill stick with the Socket class then. Although the decoding is the part where i'm stuck at. I read BlazeDS, Red5 and OpenAMF (and now GraniteDS) could fix that problem for me but then i get told i need something like Tomcat to use those, is that true? Can't i just import the decoding class and be done with it?
Also ive got 2 identical Classes, one for Flash (not flex) and the other for Java that share the same methods and use externalWrite/Read. if that's what you mean with the class-mapping?
Self encoding seems interesting but i heard good things about AMF so ill stick with that. Thanks anyway though i noted it down as a alternative,for if i fail the AMF part.
wvxvw
December 4th, 2009, 09:45 AM
Well, I'm not really a Java programmer... but, judging from PHP, I'd imagine that using the encoding classes on their own might be some work, but, usually, not to much work (you can definitely get Zend / AMFPHP to work with no connection to the server).
And, class mapping is like this:
Say, you are sending a typed object multiple times. You need to send it's description, like, what methods and properties it has, inheritance chain etc. But, since you send it many times, you can do it like so:
- first time you send all the needed description.
- you receive back an acknowledgment, that description was accepted, parsed and stored with ID=someID.
- next time you send that same object you only send the ID you received the first time.
OmniNL
December 7th, 2009, 01:36 PM
Finally got it to work, well.. sorta, the reading part that is :D
try{
//dataIn = new DataInputStream(socket.getInputStream());
int bAvailable = dataIn.available();
int bWhole;
while (bAvailable != -1) {
bWhole = dataIn.readInt();
System.out.println(bWhole);
bAvailable = dataIn.available();
}
Seriously, its that simpel, kept me busy for 3 weeks. But i'm not there yet. I want it to use the readExternal / writeExternal in my java class that is identical to my as3 class (the one that implements IExternalizable (http://dl.fancycode.com/red5/api/org/red5/io/amf3/IExternalizable.html)) . But i have no clue how to link them.. Anyone knows how? It's hard to find a good tutorial about this.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.