• Post Reply Bookmark Topic Watch Topic
  • New Topic

TCP/IP Server Question

 
Joseph Goodman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a TCP/IP server application with multiple client connections. My question is how should I handle a client connection that is reading data fast enough and is causing my application to block on writes to that client connection? I know that I could use non blocking I/O and buffer the data that does not get sent, then re-send the data when the client connection is writable. What do I do if the client gets deadlocked and my backbuffer eats up memory? Anyone ever faced this problem?



Thanks
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does your server have a thread per client? If so, blocking on the writes may not be a terrible thing. Unless you get too many threads or something. WHat kind of problems does this situation give you?
 
Joseph Goodman
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have determined that I need to block on the writes since I am sending large files to the clients. If I tried to buffer up what is being sent I could easily eat up the available memory. I guess another question I need to answer is, when do I give up on a client. Is there a timeout for a write?
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You mentioned TCP/IP ... are you also HTTP? I don't know much about the intent of chunking in HTTP ... would that help? Maybe you could read one chunk, write one chunk, repeat until done.

As for giving up on a client ... you might keep track of bytes-per-second as you write and cut anybody off who is not matching minimum bandwidth.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!