Java Tutorial - Java Script :
Here’s an example of a Java program that uses the Socket classes to implement a simple network-based server application. The TimeServer application makes a connection to any client that connects to port 4415, displays the current time, and then closes the connection. For an application to act as a server, it must monitor at least one port on the host machine for client connections. Port 4415 was chosen arbitrarily for this project, but it could be any number from 1024 to 65,535.
When a client is detected, the server creates a Date object that represents the current date and time and then sends it to the client as a String. In this exchange of information between the server and client, the server does almost all the work. The client’s only responsibility is to establish a connection to the server and display messages received from the server. Although you could develop a simple client for a project like this, you also can use any telnet application to act as the client, as long as it can connect to a port you designat . Windows includes a command-line application called telnet that you can use for this purpose.
The TimeServer application creates a server socket on port 4415. When a client connects, a PrintWriter object is constructed from buffered output stream so that a string can be sent to the client—the current time. After the string has been sent, the flush() and close() methods of the writer end the data exchange and close the socket to await new connections.