I'm making simple peer to peer game and I decided to use XML to send information over sockets(example below). But I'm not sure how to send it ? I should simply use ObjectOutputStream.writeObject(obj)
and as parameter use object
from my example ?
Mainly I'm asking, how does look proper sending XML objects over sockets.
import javax.xml.bind.JAXBContext;
import javax.xml.bind.Marshaller;
public class SendIPObject {
public static void main(String[] args) throws Exception {
JAXBContext context = JAXBContext.newInstance(IPSender.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
Player object = new Player();
object.setID(0);
object.setIP("192.167.211.167");
m.marshal(object, System.out);
}
}
import java.io.Serializable;
abstract public class Player implements Serializable{
private String ip;
private int id;
public String getIP() {
return ip;
}
public int getID() {
return id;
}
public void setIP(String ip) {
this.ip = ip;
}
public void setID(int id) {
this.id = id;
}
}