开发者

How sockets relate to common networking APIs

This morning I asked a sockets-related question, but this is a different beast and so I decided making a separate post altogether.

I now have a good idea of what sockets are, and the purpose(s) they serve. I'm trying to understand their relation to Java NIO, Java RMI, and so-called networking APIs like Netty or MINA.

  1. Are sockets the basis of all Java-based networking, and is NIO the foundation of开发者_如何学JAVA Java-based networking (i.e., is it the API that provides the socket structures for higher frameworks like Netty or MINA)? If not, then what is the foundation of Java's networking capabilities?

  2. Can one use sockets (which as I understand it, or network-layer constructs), to send (byte-wise) messages compliant with higher protocols, such as TCP or UDP, HTTP, FTP, etc? If so, I would imagine that development teams might, for example, make their own HttpProtocol library, or SSLProtocol library, yes?

  3. My understanding is that NIO is the basis of all Java networking, and that RMI, Netty, MINA, etc. all extend the NIO framework into their own implementations. Is this correct? If not, how do these frameworks relate to each other?

Thanks again for all your help!


Are sockets the basis of all Java-based networking,

For IP protocols, yes. There might be special libraries such as JavaComm for serial port communication, and JAIN for various telecom protocols that's not socket based

and is NIO the foundation of Java-based networking

Not really, sockets are. see the previous answer. NIO builds on and augments sockets though, as well as other things. The most important part is probably that NIO allows you to listen for events on several sockets in a single thread and do non-blocking IO. Netty and Mina takes advantage of the NIO apis.

NIO stands for New I/O, and was a new API for doing IO introduced in Java 1.4. It does a lot of other stuff than socket IO though. Arguably, NIO will allow you to do socket IO more efficently at the cost of more complexity.

Can one use sockets (which as I understand it, or network-layer constructs), to send (byte-wise) messages compliant with higher protocols, such as TCP or UDP,

No. Sockets gives you access to transport protocols such as TCP or UDP (actually with Java it's only TCP and UDP, in the future, probably SCTP as well). You can build stuff that works on top of TCP/UDP, not implement TCP/UDP yourself(unless you want to implement an IP stack on top of TCP or UDP - which is what several VPN or tunelling protocols does)

HTTP, FTP, etc?

Yes, these commonly work on top of TCP, you can implement HTTP, FTP and other protocols that that runs above TCP/UDP by using sockets in java - that's what sockets are for.


Sockets are the Java basic building blocks for networking. They only allow you to do basic operations: opening a connection (TCP or UDP), writing or reading bytes and closing the connection. They also handle failure cases by throwing exceptions. In the OSI model, this is the 4th layer (transport).

Higher level APIs are built on top of sockets, they allow to do more interesting tasks such as HTTP connections or SSL communication.

Java NIO is the new version of the first Java IO API. As far as networking is concerned it essentially brings a new API for non blocking sockets.

Higher level APIs are built on top of Java IO and/or Java NIO.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜