tags:

views:

135

answers:

3

Hello,

I'm currently working on a TCP socket server in C++; and I'm trying to figure out how I can ignore all browser connections made to my server. Any idea's?

Thanks.

+7  A: 

Need more details to give good feedback.

Are you going to be listening on port 80 but want to avoid all HTTP traffic? Or will your protocol be HTTP-based? Do you need to listen on 80 or can you pick any port?

If it's your own custom protocol (HTTP or not) you could just look at the first line sent up and if it's not to your liking just close() the socket.

EDIT:

Since you're going to be listening on a custom port, you probably won't get any browser traffic anyhow. Further, since you're going to be writing your own protocol, just require a handshake which establishes your client speaks your custom protocol and then ignore (close()) everything else.

Bonus points: depending on your goal, send back an HTTP error message which can be displayed to the user.

DarkSquid
Listening on a custom port, and I want to avoid all HTTP traffic on that port.
Chaoz
Why would you expect http traffic if it's not an http port?
Paul Tomblin
A: 

Just look at the differences between valid connection requests and invalid ones (i.e. dump both request types to examine each request), in your specific case, you'll want to look at the HTTP request header to ignore all such requests (assuming that valid requests do not make use of HTTP).

none
+1  A: 

You can't stop a web-browser initiated tcp-session from connecting to your tcp server. You can (as stated above) close the connection once you've detected the client is trying to talk http to you (or any other unwanted application-layer protocol).

nikudesu