[java] Sending array of integers over the network to an applet
Hi...
I want to load up an image on my server manipulate it''s data then send it over the internet into an applet and display it.
How can I send the image buffer that was captured with PixelGrabber form my servlet to the applet with writting each value one bu one is it possible?
Hardcore Until The End.
two ways. If you can use RMI then do so. I feel it is very easy. The other way is to use streams. The applet should open a socket to the server. Then the server needs to listen for the socket, get an outputstream from the socket, and make an object output stream from that outputstream. The class of the object that you want to send needs to implement serializable, then the server will write the object to the stream like this, object.writeObject(ObjOutputStream); On the applet side after you open the socket you need to hook up an Object input stream on to the socket and to object.readObject(ObjInputStream); Then I think you need to cast it into the appropriate type.
If you don't have an object but just an array of bytes from the PixelGrabber, you can substitute ByteArrayOutputStream for ObjectOutputStream. The only difference is that when you make the BAOS you don't give it an output stream, only when you do BAOS.writeTo(OutputStream); Just check out the javadocs for java.io.* and java.net.Socket.
There is a third way to do this actually, just manipulate the image inside the applet. It should be a lot easier to just load the image and manipulate it than to go through the mess of serializing it. But maybe that's not possible. Another advantage of using RMI is that you can perform callbacks from the server. The client can make remote method calls on remote objects, and the server can automatically respond to the client with certain other methods.
Edited by - Jim_Ross on August 4, 2000 12:47:55 PM
If you don't have an object but just an array of bytes from the PixelGrabber, you can substitute ByteArrayOutputStream for ObjectOutputStream. The only difference is that when you make the BAOS you don't give it an output stream, only when you do BAOS.writeTo(OutputStream); Just check out the javadocs for java.io.* and java.net.Socket.
There is a third way to do this actually, just manipulate the image inside the applet. It should be a lot easier to just load the image and manipulate it than to go through the mess of serializing it. But maybe that's not possible. Another advantage of using RMI is that you can perform callbacks from the server. The client can make remote method calls on remote objects, and the server can automatically respond to the client with certain other methods.
Edited by - Jim_Ross on August 4, 2000 12:47:55 PM
byte array is for bytes though not 32 bit ints...
Do you have some source lyinga round, I dont care about the details connectiong between servlet and applet that I have already.
Do you have some source lyinga round, I dont care about the details connectiong between servlet and applet that I have already.
Hardcore Until The End.
Byte arrays can transfer any data type..a 32 bit integer is 4 bytes, transferring it across the stream just means you need to write it into a 32 bit buffer on the other side to reconstruct it as a integer.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement