How to read huge data on a socket and also write to socketchannel

How to read very large data using a DataInputStream socket If the data is in String format and is more than 1,000,000 characters long.

Also how to write big data using SocketChannel in java?

0


a source to share


1 answer


The problem is your data is coming in chunks. Either the packet size is limited or the DataInputStream has an internal buffer of only 40k. I don't know, but it doesn't matter. In any case, all 1,000,000 bytes will not arrive at once. Therefore, you must rewrite your program to expect this. You need to read the smaller chunks you get and store them in another byte [1,000,000] variable (keeping track of where your last byte index is). Continue looping until you've finished reading the socket. Then you can work with your internal variable.



+1


a source







All Articles