how to... join DatagramPacket and Serializable
Hi!
Here's what I want to achieve:
I want to send a packet much more bigger than 256bytes. My serializable object has about 4000bytes. And I want send him to Client. How to do that? Everything is working while an object has not more than 256bytes. If it's more, there's exception like:
java.io.EOFException
at java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2279)
at java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(ObjectInputStream.java:3017)
...
Is there any better method to send packets of any size?
[593 byte] By [
blelumpa] at [2007-11-27 4:55:51]

# 4
/////////////////// Server
ServerSocket serverSocket;
try {
serverSocket = new ServerSocket(4444);
ObjectOutputStream out;
Socket clientSocket = serverSocket.accept();
ObjectInputStream in = new ObjectInputStream(clientSocket.getInputStream());
Object temp=in.readObject();
javax.swing.JButton button = (javax.swing.JButton)temp;
clientSocket = serverSocket.accept();
out = new ObjectOutputStream(clientSocket.getOutputStream());
JLabel label = new JLabel("lab");
out.flush();
out.writeObject(label);
out.flush();
in.close();
out.close();
clientSocket.close();
}
catch (IOException e1) {
e1.printStackTrace();
}
catch(ClassNotFoundException e) {
e.printStackTrace();
}
///////////////// Client
[code]
Socket socket = new Socket("localhost", 4444);
JButton butt = new JButton("button");
ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream());
out.flush();
out.writeObject(butt);
out.flush();
ObjectInputStream in = new ObjectInputStream(socket.getInputStream());
Object temp=in.readObject();
in.close();
out.close();
socket.close();
and well Server gets the JButton object (and sends JLabel object aswell) but client doesn't want get JLabel object. there's exception:
Exception in thread "main" java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1838)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1747)
at java.io.ObjectOutputStream.writeNonProxyDesc(ObjectOutputStream.java:1249)
at java.io.ObjectOutputStream.writeClassDesc(ObjectOutputStream.java:1203)
at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1387)
at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
at java.io.ObjectOutputStream.writeFatalException(ObjectOutputStream.java:1538)
at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:329)
what I'm doing wrong?