i working on simple application transfers screenshots across sockets. screenshot instantiating , using robot class follows:
private robot robot; public robot getrobot(){ if(robot == null){ try{ robot = new robot(); }catch(exception e){} } return robot; } public bufferedimage screenshot(){ return getrobot().createscreencapture(getscreenrectangle()); } public byte[] getbytes(bufferedimage image){ byte[] data = null; try{ bytearrayoutputstream baos = new bytearrayoutputstream(); imageio.write(img, "png", baos); data = baos.tobytearray(); baos.close(); }catch(ioexception e){} return data; } i use getbytes method above convert bufferedimage byte array written socket output stream. image average of 500kb. more efficient split 500kb smaller segments of 5kb or better keep in larger chunks of 30kb. main aim here speed , accuracy of delivery. appreciate reasoning of why either way more effective in these terms other.
the network packet size limited called mtu, can't send packet bigger mtu. mtu, can check link, not big (i believe 1500 bytes more common mtu ethernet). network side; on java side deciding segment size depend on number of images transmitted concurrently (if send 100 image concurrently have 100 segments allocated).
my suggestion try segment size less mtu (i guess using tcp/ip must consider tcp , ip header size) , see happens.
edit: comments point out (correctly) form java perspective mtu not affect how data should chunked; true packet bigger mtu since tcp/ip layer breaks larger chunks of data in smaller units; poster wants know if there "best" buffer size; , response on mtu there no benefit (for network transmission) in increasing buffer size @ java side
Comments
Post a Comment