public class

NetworkServer

extends Object
implements Cloneable Runnable
java.lang.Object
   ↳ sun.net.NetworkServer

Class Overview

This is the base class for network servers. To define a new type of server define a new subclass of NetworkServer with a serviceRequest method that services one request. Start the server by executing:

      new MyServerClass().startServer(port);
 

Summary

Fields
public InputStream clientInput Buffered stream for reading replies from client.
public PrintStream clientOutput Stream for printing to the client.
public Socket clientSocket Socket for communicating with client.
Public Constructors
NetworkServer()
Public Methods
boolean clientIsOpen()
Return client connection status
Object clone()
Clone this object;
void close()
Close an open connection to the client.
static void main(String[] argv)
final void run()
When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.
void serviceRequest()
Service one request.
final void startServer(int port)
Start a server on port port.
[Expand]
Inherited Methods
From class java.lang.Object
From interface java.lang.Runnable

Fields

public InputStream clientInput

Buffered stream for reading replies from client.

public PrintStream clientOutput

Stream for printing to the client.

public Socket clientSocket

Socket for communicating with client.

Public Constructors

public NetworkServer ()

Public Methods

public boolean clientIsOpen ()

Return client connection status

public Object clone ()

Clone this object;

Returns
  • a clone of this instance.

public void close ()

Close an open connection to the client.

Throws
IOException

public static void main (String[] argv)

public final void run ()

When an object implementing interface Runnable is used to create a thread, starting the thread causes the object's run method to be called in that separately executing thread.

The general contract of the method run is that it may take any action whatsoever.

public void serviceRequest ()

Service one request. It is invoked with the clientInput and clientOutput streams initialized. This method handles one client connection. When it is done, it can simply exit. The default server just echoes it's input. It is invoked in it's own private thread.

Throws
IOException

public final void startServer (int port)

Start a server on port port. It will call serviceRequest() for each new connection.

Throws
IOException