I'm writing a program where the server draws a shape in its app and the client can see that shape in its own app. I thought about converting the object to a byte array but it didn't do anything.
The server code
private void sendShape(Graphics drawedShape) {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try {
ObjectOutputStream oos = new ObjectOutputStream(bos);
oos.writeObject(drawedShape);
oos.flush();
byte[] yourBytes = bos.toByteArray();
/*oos.writeObject(drawedShape);
oos.flush();
dispMessage("\n Teacher:" + "Shape sent!");*/
} catch (IOException e) {
jta.append("\nError");
}
}
The client code
private void processConn() throws IOException {
send("Successful");
setButtonEnabled(true);
String msg = "";
Graphics object;
ByteArrayInputStream bis = null;
do {
try
{
Object incomingObject = ois.readObject();
if(incomingObject.getClass().toString().contains("Graphics"))
{
try {
ois = new ObjectInputStream(bis);
Object o = ois.readObject();
/*object = (Graphics) ois.readObject();
dispMessage("\n" + object);*/
}finally {
try {
if (ois != null) {
ois.close();
}
} catch (IOException ex) {
}
}
}