Buffering Network Connections

I am building two applications (well, one application and one applet) that communicate over a network using TCP. The application, which is the server, is continually spitting out data from a sensor every 10 ms. The applet is receiving these data by reading through a buffered reader and graphing them. The whole point of this is to get a "real-time" glimpse of the data that the sensor is recording. However, the applet also supports "pausing," in that the applet will stop reading from the network connection and will stop graphing, but will allow the user to interact with the graph. The way it is implemented is the simplest. I know that it is simple, but I am concerned that the SO_RCVBUF (and or the buffer of the buffered reader) will fill up if the user keeps the graph paused for a long time.

Basically, I want to know what happens to the data when these buffers are full? More specifically:

1) Will the bufferedreader always read data into its buffer, even if the buffer is full and it has to overwrite data)?

2) If the SO_RCVBUF is full, will TCP send an error packet to the server? Will it just overwrite the buffer?

3) Is it OK for the buffers to be full (and/or "overflow" in the sense that the amount of data to be stored in the buffer is greater than the size of the buffer, not the security vulnerability sense)? I do not care if some data gets thrown away, I just want to know if java, TCP or the server will complain if this happens.

I can post code if it is necessary, but I can't think of what code to post in relation to my question.

Thanks,

geffde

[1621 byte] By [geffdea] at [2007-11-27 9:00:15]
# 1

If the reader stops reading and its receive buffer fills up and the sender's send buffer fills up, the sender will block.

You can get around that by sending via non-blocking NIO, but that raises the question of what to do with the data that can't be written. If it's not OK to just lose it, you have a problem ...

ejpa at 2007-7-12 21:28:42 > top of Java-index,Core,Core APIs...
# 2

I can lose all the data I want. I just don't want the sender to get messed up.

So, just to make sure I understand this correctly, if the sender is doing all network IO in its own thread, then the blocking won't matter?

I realize that I can just have the reader read and do nothing with the data* (and that solves the buffer filling problems), but the question has really been bugging me and I haven't found any information about it on the web.

*(pseudo)code to accomplish that:

while(running)

{

if((bufferedreader.read(data, 0, 5) > 0) && recordData)

displayData(data);

}

where recordData is a boolean that determines whether I am in the graphing state or not.

geffdea at 2007-7-12 21:28:42 > top of Java-index,Core,Core APIs...
# 3

> So, just to make sure I understand this correctly, if

> the sender is doing all network IO in its own thread,

> then the blocking won't matter?

Not what I said at all. If the sender is doing blocking I/O via sockets, it will block. Nothing to do with threads.

The only solution is what I said before: NIO in non-blocking mode. Channel.write() will eventually return zero when this condition occurs: just clear the buffer and continue. Maybe log it.

ejpa at 2007-7-12 21:28:42 > top of Java-index,Core,Core APIs...