Wednesday, July 25, 2007

Network Communications

Communication between computers is a nightmare, whether it's a web server or a multi-player FPS. How do you know when a client has finished sending you data? Does it disconnect? Does the stream contain an EOF signal? Does the client tell you how many bytes it's going to send?

I've just been trying to write a simple web proxy server, and this is just one of the questions that is proving hard to answer. Some websites (like Google) don't send a content-length (and I don't think it even disconnects once it's finished sending the data). So even if you want to write a simple proxy server that (on the face of it) just passes the bytes between computers, you have to write a piece of software that almost amounts to pretty much a full web server and partial web browser (except without the rendering features).

However, it's more compicated than that because you have to handle the communication two ways for each "connection". So you get the added complication of slow clients (client that connect to a server, and then decide to wait a few milliseconds before actually sending a request). Then there's flushing - when to flush and when to not.

Even though my Proxy now seems to be working for most websites, for some reason it can't read Slashdot (I get a blank response) and Googlemail says it's received a bad request. Gawd knows why.

No comments: