Sorry dat het in het engels is, maar ik wou het posten op het Sun forum, maar dat werkte weer eens niet 
Hi there,
We're working on an application that should transfer objects over a network. We encode and decode the objects with the java.beans.XMLEncoder and XMLDecoder classes. The application can transfer the xml data via HTTP and via Sockets, but with the socket tranfer some problems have occured.
First of all, when we tried to XMLEncode object directly onto the clients socket outputstream and XMLDecode from the socket on the server, nothing happened. After a quick look in the source files, we noticed we had to close the XMLEncoder, since otherwise it would not send the </java> end tag. However, closing the XMLEncoder causes the underlying stream to close. Normally this should not be a problem, but closing a sockets outputstream will, to our surprise, also close the socket.
To fix this we kept a refference to the socket outputstream the XMLEncoder writes to and manually printed the </java> end tag on the stream once the object transfer was complete. Although the xml is transferred succesfully using this workaround, the XMLDecoder will not start decoding, probably because it waits for the end of the stream. To get around this one we had to shut down the output on the client socket (default API method).
Once we had fixed this the XMLDecoder on the server did its job, but when server wanted to send back its response to the client, it started complaining that the socket was closed! Evidently shutting down a client sockets output will completely shut down the server socket (the socket used by the server, not a ServerSocket
). The only workaround we haven't tried is using some kind of PipedOutput/Input pair around both sockets, so we can close streams without closing the socket. Although this might actually work, it's not a very efficient, elegant or even easy solution.
Does anyone have any idea on how to solve this? And isn't the socket behaviour described above some kind of bug?
Thanks in advance and if you can fix this, you'll defenitely have earned some DukeDollars
btw.: we also tried sending a whole bunch of platform dependend End Of Stream characters through the socket to get the XMLDecoder to do something, but to no avail.
Hi there,
We're working on an application that should transfer objects over a network. We encode and decode the objects with the java.beans.XMLEncoder and XMLDecoder classes. The application can transfer the xml data via HTTP and via Sockets, but with the socket tranfer some problems have occured.
First of all, when we tried to XMLEncode object directly onto the clients socket outputstream and XMLDecode from the socket on the server, nothing happened. After a quick look in the source files, we noticed we had to close the XMLEncoder, since otherwise it would not send the </java> end tag. However, closing the XMLEncoder causes the underlying stream to close. Normally this should not be a problem, but closing a sockets outputstream will, to our surprise, also close the socket.
To fix this we kept a refference to the socket outputstream the XMLEncoder writes to and manually printed the </java> end tag on the stream once the object transfer was complete. Although the xml is transferred succesfully using this workaround, the XMLDecoder will not start decoding, probably because it waits for the end of the stream. To get around this one we had to shut down the output on the client socket (default API method).
Once we had fixed this the XMLDecoder on the server did its job, but when server wanted to send back its response to the client, it started complaining that the socket was closed! Evidently shutting down a client sockets output will completely shut down the server socket (the socket used by the server, not a ServerSocket
Does anyone have any idea on how to solve this? And isn't the socket behaviour described above some kind of bug?
Thanks in advance and if you can fix this, you'll defenitely have earned some DukeDollars
btw.: we also tried sending a whole bunch of platform dependend End Of Stream characters through the socket to get the XMLDecoder to do something, but to no avail.