FileDocCategorySizeDatePackage
TelnetTestSimpleServer.javaAPI DocApache Commons NET 1.4.1 API3895Sat Dec 03 10:05:48 GMT 2005org.apache.commons.net.telnet

TelnetTestSimpleServer

public class TelnetTestSimpleServer extends Object implements Runnable
Simple TCP server. Waits for connections on a TCP port in a separate thread.

author
Bruno D'Avanzo

Fields Summary
ServerSocket
serverSocket
Socket
clientSocket
Thread
listener
Constructors Summary
public TelnetTestSimpleServer(int port)
test of client-driven subnegotiation.

param
port - server port on which to listen.


                       
        
    
        serverSocket = new ServerSocket(port);

        listener = new Thread (this);

        listener.start();
    
Methods Summary
public voiddisconnect()
Disconnects the client socket

        synchronized (clientSocket)
        {
            try
            {
                clientSocket.notify();
            }
            catch (Exception e)
            {
                System.err.println("Exception in notify, "+ e.getMessage());
            }
        }
    
public java.io.InputStreamgetInputStream()
Gets the input stream for the client socket

        if(clientSocket != null)
        {
            return(clientSocket.getInputStream());
        }
        else
        {
            return(null);
        }
    
public java.io.OutputStreamgetOutputStream()
Gets the output stream for the client socket

        if(clientSocket != null)
        {
            return(clientSocket.getOutputStream());
        }
        else
        {
            return(null);
        }
    
public voidrun()
Run for the thread. Waits for new connections

        boolean bError = false;
        while(!bError)
        {
            try
            {
                clientSocket = serverSocket.accept();
                synchronized (clientSocket)
                {
                    try
                    {
                        clientSocket.wait();
                    }
                    catch (Exception e)
                    {
                        System.err.println("Exception in wait, "+ e.getMessage());
                    }
                    try
                    {
                        clientSocket.close();
                    }
                    catch (Exception e)
                    {
                        System.err.println("Exception in close, "+ e.getMessage());
                    }
                }
            }
            catch (IOException e)
            {
                bError = true;
            }
        }

        try
        {
            serverSocket.close();
        }
        catch (Exception e)
        {
            System.err.println("Exception in close, "+ e.getMessage());
        }
    
public voidstop()
Stop the listener thread

        listener.interrupt();
        try
        {
            serverSocket.close();
        }
        catch (Exception e)
        {
            System.err.println("Exception in close, "+ e.getMessage());
        }