4

Is there a way in Java to know if an HTTP request was received over TCP or over UDP?

11
  • See serverfault.com/questions/98951/does-https-use-tcp-or-udp for general HTTP information Commented Jul 1, 2015 at 13:29
  • Hi! I know http usually does not run over udp, but it does not mean it's not possible. And I was thinking that this could be a security issue. So I was wandering if it's even possible... Commented Jul 1, 2015 at 13:31
  • add code example, how you perform a request. Commented Jul 1, 2015 at 13:32
  • @Algosub There's no Java EE server that can do HTTP over UDP, so there's no means to check whether it's UDP - it's always TCP. Commented Jul 1, 2015 at 13:35
  • 1
    @Algosub I'm sure. It's probably not referenced in any single place. The closest thing you'll find is the RFC for HTTP, which specifies TCP as the standard protocol, and would not allow the use of UDP since HTTP requires a reliable protocol. You would have to go and look through the features (or source code) of all the Java EE servers - you'll find that they do not do HTTP over UDP. Commented Jul 1, 2015 at 13:46

2 Answers 2

6

Quote from the RFC2616

HTTP communication usually takes place over TCP/IP connections. The default port is TCP 80 [19], but other ports can be used. This does not preclude HTTP from being implemented on top of any other protocol on the Internet, or on other networks. HTTP only presumes a reliable transport; any protocol that provides such guarantees can be used; the mapping of the HTTP/1.1 request and response structures onto the transport data units of the protocol in question is outside the scope of this specification.

I would say this eliminates default UDP. Other Reliable forms of protocols would still be possible

Sign up to request clarification or add additional context in comments.

Comments

1

As @ceekay says, RFC tells that HTTP uses reliable transport only, so that means no way for UDP. But one may try to build some other protocol on top of UDP, or may be do not use TCP/IP stack at all.. But as your question is about Java, then the answer is - this is all about Java libraries and frameworks used. Actually all the libraries that I know, like HtmlUnit http://htmlunit.sourceforge.net for example, hide this information from you. So you are dealing with HTTP(s) only without knowing details about underground transport. But in theory this is possible that some library will show this information for you.

But actually I do not see a way why this may be importatnt for you (in 99.999999% HTTP will use TCP). If you tell us why you are asking that strange question, then maybe we will answer you more specific.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.