CADI.Client.Network
Class ClientSocket

java.lang.Object
  extended by java.net.Socket
      extended by CADI.Client.Network.ClientSocket

public class ClientSocket
extends java.net.Socket

This class inherits the Socket adding new useful methods and other ones has been overrided and adapted to new requirements.

Version:
1.0 2007/10/27
Author:
Group on Interactive Coding of Images (GICI)

Field Summary
private  boolean connected
           
static int DEFAULT_PORT
          The default port.
private  int DEFAULT_TIMEOUT
           
private  int port
          It is the server port where request must be sent.
private  java.lang.String server
          Contains the JPIP server name.
private  int timeout
           
 
Constructor Summary
ClientSocket()
           
 
Method Summary
 void close()
           
 void connect(java.lang.String server)
          Opens a connection between the client and the server.
 void connect(java.lang.String server, int port)
          Opens a connection between the client and the server.
 void connect(java.lang.String server, int port, int timeout)
          Opens a connection between the client and the server.
 java.io.InputStream getInputStream()
           
 java.io.OutputStream getOutputStream()
           
 java.lang.String getRemoteHost()
          Returns the name of the endpoint this client is connected to, or null if it is unconnected.
 boolean isConnected()
           
 void list(java.io.PrintStream out)
          Prints this ClientSocket out to the specified output stream.
 void reconnect()
          Reconnects the socket using the last server, port, and timeout.
 void setSoTimeout(int timeout)
           
 java.lang.String toString()
          For debugging purposes.
 
Methods inherited from class java.net.Socket
bind, connect, connect, getChannel, getInetAddress, getKeepAlive, getLocalAddress, getLocalPort, getLocalSocketAddress, getOOBInline, getPort, getReceiveBufferSize, getRemoteSocketAddress, getReuseAddress, getSendBufferSize, getSoLinger, getSoTimeout, getTcpNoDelay, getTrafficClass, isBound, isClosed, isInputShutdown, isOutputShutdown, sendUrgentData, setKeepAlive, setOOBInline, setPerformancePreferences, setReceiveBufferSize, setReuseAddress, setSendBufferSize, setSocketImplFactory, setSoLinger, setTcpNoDelay, setTrafficClass, shutdownInput, shutdownOutput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

server

private java.lang.String server
Contains the JPIP server name.


port

private int port
It is the server port where request must be sent.


DEFAULT_PORT

public static final int DEFAULT_PORT
The default port.

See Also:
Constant Field Values

timeout

private int timeout

DEFAULT_TIMEOUT

private int DEFAULT_TIMEOUT

connected

private boolean connected
Constructor Detail

ClientSocket

public ClientSocket()
Method Detail

connect

public void connect(java.lang.String server)
             throws java.io.IOException
Opens a connection between the client and the server. This connection is kept opened until the close() method is called.

Parameters:
server - the server name.
Throws:
java.io.IOException - an IOException will be thrown is the connection can not be opened.

connect

public void connect(java.lang.String server,
                    int port)
             throws java.io.IOException
Opens a connection between the client and the server. This connection is kept opened until the close() method is called.

Parameters:
server -
port -
Throws:
java.io.IOException - an IOException will be thrown is the connection can not be opened.

connect

public void connect(java.lang.String server,
                    int port,
                    int timeout)
             throws java.io.IOException
Opens a connection between the client and the server. This connection is kept opened until the close() method is called.

Parameters:
server -
port -
timeout -
Throws:
java.io.IOException - an IOException will be thrown is the connection can not be opened.

reconnect

public void reconnect()
               throws java.io.IOException
Reconnects the socket using the last server, port, and timeout.

Throws:
java.io.IOException

close

public void close()
Overrides:
close in class java.net.Socket

isConnected

public boolean isConnected()
Overrides:
isConnected in class java.net.Socket

getInputStream

public java.io.InputStream getInputStream()
                                   throws java.io.IOException
Overrides:
getInputStream in class java.net.Socket
Throws:
java.io.IOException

getOutputStream

public java.io.OutputStream getOutputStream()
                                     throws java.io.IOException
Overrides:
getOutputStream in class java.net.Socket
Throws:
java.io.IOException

getRemoteHost

public java.lang.String getRemoteHost()
Returns the name of the endpoint this client is connected to, or null if it is unconnected.

Returns:
the name of the remote host.

setSoTimeout

public void setSoTimeout(int timeout)
                  throws java.net.SocketException
Overrides:
setSoTimeout in class java.net.Socket
Throws:
java.net.SocketException

toString

public java.lang.String toString()
For debugging purposes. It shows all socket information.

Overrides:
toString in class java.net.Socket

list

public void list(java.io.PrintStream out)
Prints this ClientSocket out to the specified output stream. This method is useful for debugging.

Parameters:
out - an output stream.


CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

Group on Interactive Coding of Images (GICI) (contact)