Java: ignoring input stream - will there be buffer overflows and what happens badly?

I have a client connecting to my server. The client sends some messages to the server that I don’t care about and don’t want to waste time parsing messages if I don’t use them. All I / I use is just java i / o, not nio.

If I create an input stream and just do not read it, can this buffer fill up and cause problems? If so, is there something that I can do, or a property that I can set, so that it just throws away the data that it sees?

Now, what if the server does not create an input stream at all? Will this cause client / send problems?

Please let me know.

Thanks JBU

+3
source share
5 answers

When you acceptconnect to the client, you receive InputStream. If you do not read from this stream, client data will be buffered. In the end, the buffer will fill up and the client will block when it tries to write more data. If the client writes all of its data before reading the response from the server, you will get a pretty classic deadlock situation. If you really don't need data from the client, just read (or call skip) before EOF and discard the data. Alternatively, if it is not a standard request / response protocol (such as HTTP), start a new stream that reads the stream continuously so that it does not support backup.

+5
source

, ?

+2

, Java - , , .

InputStream , ?

+1

, InputStream , , , , ( tomcat) ( ).

.

0
InputStream in = ....
byte[] buffer = new byte[4096] // or whatever
while(true)
  in.read(buffer);

if you accept the connection, you must read the data. to tell you that I have never seen (or never seen) a situation where this (a server that ignores all data) can be useful.

0
source

Source: https://habr.com/ru/post/1715910/


All Articles