Skip to Main Content

Java APIs

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to transfer large datagram packet via MulticastSocket

843790Jun 25 2010 — edited Jul 29 2010
Hi all, i'm trying to do a program with capable to capture screen and send out through MulticastSocket. I'm able to do everything and send out which the packet must be below 65535 Byte. Any packet more than 65535 Byte would not able to send out.
An original captured image file size is approximately about 300K Byte.
I also tried to reduce the image quality, but it doesn't look nice, because the image can't even present properly after the quality adjustment.
I'm wondering is there any other method to send out the packet without any compression or any good compression but good image quality remain??
But i'm looking for more better packet transmission for packet size more than 65535 Byte...
These are the code:
InetAddress multicastAddress = InetAddress.getByName("224.5.6.7");
socket = new MulticastSocket(6789);
Robot robot = new Robot();

//Capture Image 
BufferedImage bufferedImage = robot.createScreenCapture(new Rectangle(Toolkit.getDefaultToolkit().getScreenSize()));
Iterator<ImageWriter> writers = ImageIO.getImageWritersBySuffix("jpeg");
if (!writers.hasNext()) throw new IllegalStateException("No writers found");
ImageWriter writer = (ImageWriter) writers.next();

//Set Image Quality
ImageWriteParam param = writer.getDefaultWriteParam();
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
//param.setCompressionQuality(1);
param.setCompressionQuality(0.2f); //So far 0.2f is the highest compression and highest quality to transfer, approximately 30K~50K size of packet

//Write/Change Image Quality
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ImageOutputStream ios = ImageIO.createImageOutputStream(bos);
writer.setOutput(ios);
writer.write(null, new IIOImage(bufferedImage, null, null), param);
ios.flush();

//Send packet
DatagramPacket sendPacket = new DatagramPacket(bos.toByteArray(), bos.toByteArray().length ,multicastAddress,6789);
socket.send(sendPacket); //Packet size cannot larger than 65535 Byte
Thanks in advance :)

Edited by: nick_khor on Jun 25, 2010 6:01 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 26 2010
Added on Jun 25 2010
15 comments
1,685 views