sockets - How DataOutput.writeByte()/DataInput.readByte() or other equivalent works in Java? -


byte[] message = ... socket socket = ... dataoutputstream dout = new dataoutputstream(socket.getoutputstream());  dout.write(message);  //#1 ... //other code  

let assume machine 1 (with code above) trying send somethings machine 2 trying read byte machine 1.

according tcp, can codes after line #1 not execute if machine 2 has not yet read data sent above?

but @ point, can machine 2 read data , codes after line #1 execute? happens @ operating system level or application level? example, machine 2 os buffer message machine 1 right after machine 1 execute writebyte command/statement, machine 2 signal machine 1 proceed line #1?

or machine 2 signal machine 1 proceed if java application execute readbyte command/statement @ application level?

if whole receiving process happens @ os level, how can control buffer size used cache incoming data (in machine 2)?

tcp has local buffers. java not handle comms, handled os. java accesses local buffers, reads empty bytes out of buffer , writes put bytes buffer.

blocking io behaves blocking if try read empty buffer or write full buffer.

on receipt of block of data client send ack sender. sender empty data buffer on receipt of ack.

bear in mind various routers , switches along route may have own buffers , sender may receive ack prior client receiving data.

buffer size can set using setreceivebuffersize , setsendbuffersize methods.

http://docs.oracle.com/javase/7/docs/api/java/net/socket.html


Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -