Kicking it old school: I'm using Java SE 5 (or java v1.5) (please don't tell me to upgrade, because for what I'm working on [which is private] I need to use this version of java).
I need help setting up a web client/server application. Every variation I've looked for online has narrowed down to using websockets/sockets, however the version of java I'm using does not have sockets yet.
Does anyone have a tutorial for setting up a client/server model application not using sockets, or some sample code that can point me in the correct direction?
EDIT: Okay, so apparently my version of java does have sockets. I'll look into that more. However, now I'm just curious, how does one create a java server not using sockets?
You need sockets. They serve as the end-points to the connection. Although, you can use alternatives to the blocking
Socket
andServerSocket
implementations.NIO (New IO) uses channels. It allows for non-blocking I/O:
Using a Selector (optional, but recommended)
You could use a
Selector
to switch between reading/writing/accepting to allow blocking only when theres nothing to do (to remove excess CPU usage)SelectionKey
supports accepting viaisAcceptable()
, reading viaisReadable()
and writing viaisWritable()
, so you can handle all 3 on the same thread.This is a basic example of accepting a connection using NIO. I highly suggest looking into it a bit more to get a better understanding of how things work.
Here's the API documentation of the class
Socket
from Java 5.Sockets are such a basic abstraction of network communication that you'd be hard pushed to find an OS which doesn't support them, let alone a high level programming language.