FileDocCategorySizeDatePackage
SocketImpl.javaAPI DocJava SE 6 API11398Tue Jun 10 00:25:42 BST 2008java.net

SocketImpl

public abstract class SocketImpl extends Object implements SocketOptions
The abstract class SocketImpl is a common superclass of all classes that actually implement sockets. It is used to create both client and server sockets.

A "plain" socket implements these methods exactly as described, without attempting to go through a firewall or proxy.

author
unascribed
version
1.45, 03/08/07
since
JDK1.0

Fields Summary
Socket
socket
The actual Socket object.
ServerSocket
serverSocket
protected FileDescriptor
fd
The file descriptor object for this socket.
protected InetAddress
address
The IP address of the remote end of this socket.
protected int
port
The port number on the remote host to which this socket is connected.
protected int
localport
The local port number to which this socket is connected.
Constructors Summary
Methods Summary
protected abstract voidaccept(java.net.SocketImpl s)
Accepts a connection.

param
s the accepted connection.
exception
IOException if an I/O error occurs when accepting the connection.

protected abstract intavailable()
Returns the number of bytes that can be read from this socket without blocking.

return
the number of bytes that can be read from this socket without blocking.
exception
IOException if an I/O error occurs when determining the number of bytes available.

protected abstract voidbind(java.net.InetAddress host, int port)
Binds this socket to the specified local IP address and port number.

param
host an IP address that belongs to a local interface.
param
port the port number.
exception
IOException if an I/O error occurs when binding this socket.

protected abstract voidclose()
Closes this socket.

exception
IOException if an I/O error occurs when closing this socket.

protected abstract voidconnect(java.lang.String host, int port)
Connects this socket to the specified port on the named host.

param
host the name of the remote host.
param
port the port number.
exception
IOException if an I/O error occurs when connecting to the remote host.

protected abstract voidconnect(java.net.InetAddress address, int port)
Connects this socket to the specified port number on the specified host.

param
address the IP address of the remote host.
param
port the port number.
exception
IOException if an I/O error occurs when attempting a connection.

protected abstract voidconnect(java.net.SocketAddress address, int timeout)
Connects this socket to the specified port number on the specified host. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.

param
address the Socket address of the remote host.
param
timeout the timeout value, in milliseconds, or zero for no timeout.
exception
IOException if an I/O error occurs when attempting a connection.
since
1.4

protected abstract voidcreate(boolean stream)
Creates either a stream or a datagram socket.

param
stream if true, create a stream socket; otherwise, create a datagram socket.
exception
IOException if an I/O error occurs while creating the socket.

protected java.io.FileDescriptorgetFileDescriptor()
Returns the value of this socket's fd field.

return
the value of this socket's fd field.
see
java.net.SocketImpl#fd

	return fd;
    
protected java.net.InetAddressgetInetAddress()
Returns the value of this socket's address field.

return
the value of this socket's address field.
see
java.net.SocketImpl#address

	return address;
    
protected abstract java.io.InputStreamgetInputStream()
Returns an input stream for this socket.

return
a stream for reading from this socket.
exception
IOException if an I/O error occurs when creating the input stream.

protected intgetLocalPort()
Returns the value of this socket's localport field.

return
the value of this socket's localport field.
see
java.net.SocketImpl#localport

	return localport;
    
protected abstract java.io.OutputStreamgetOutputStream()
Returns an output stream for this socket.

return
an output stream for writing to this socket.
exception
IOException if an I/O error occurs when creating the output stream.

protected intgetPort()
Returns the value of this socket's port field.

return
the value of this socket's port field.
see
java.net.SocketImpl#port

	return port;
    
java.net.ServerSocketgetServerSocket()

	return serverSocket;
    
java.net.SocketgetSocket()

	return socket;
    
protected abstract voidlisten(int backlog)
Sets the maximum queue length for incoming connection indications (a request to connect) to the count argument. If a connection indication arrives when the queue is full, the connection is refused.

param
backlog the maximum length of the queue.
exception
IOException if an I/O error occurs when creating the queue.

voidreset()

   	address = null;
    	port = 0;
    	localport = 0;
    
protected abstract voidsendUrgentData(int data)
Send one byte of urgent data on the socket. The byte to be sent is the low eight bits of the parameter

param
data The byte of data to send
exception
IOException if there is an error sending the data.
since
1.4

protected voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets performance preferences for this socket.

Sockets use the TCP/IP protocol by default. Some implementations may offer alternative protocols which have different performance characteristics than TCP/IP. This method allows the application to express its own preferences as to how these tradeoffs should be made when the implementation chooses from the available protocols.

Performance preferences are described by three integers whose values indicate the relative importance of short connection time, low latency, and high bandwidth. The absolute values of the integers are irrelevant; in order to choose a protocol the values are simply compared, with larger values indicating stronger preferences. Negative values represent a lower priority than positive values. If the application prefers short connection time over both low latency and high bandwidth, for example, then it could invoke this method with the values (1, 0, 0). If the application prefers high bandwidth above low latency, and low latency above short connection time, then it could invoke this method with the values (0, 1, 2). By default, this method does nothing, unless it is overridden in a a sub-class.

param
connectionTime An int expressing the relative importance of a short connection time
param
latency An int expressing the relative importance of low latency
param
bandwidth An int expressing the relative importance of high bandwidth
since
1.5

	/* Not implemented yet */
    
voidsetServerSocket(java.net.ServerSocket soc)

	this.serverSocket = soc;
    
voidsetSocket(java.net.Socket soc)

	this.socket = soc;
    
protected voidshutdownInput()
Places the input stream for this socket at "end of stream". Any data sent to this socket is acknowledged and then silently discarded. If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.

exception
IOException if an I/O error occurs when shutting down this socket.
see
java.net.Socket#shutdownOutput()
see
java.net.Socket#close()
see
java.net.Socket#setSoLinger(boolean, int)
since
1.3

   

                                                                                      
          

                                                                             
            

                                                                               
            

                                                      	                                               
            

                                                                
            

                                                                        
          

                                                    
          

                                                       
         

                                                         
         

                                                                                   
         

                          
         

                                                                         
         
      throw new IOException("Method not implemented!");
    
protected voidshutdownOutput()
Disables the output stream for this socket. For a TCP socket, any previously written data will be sent followed by TCP's normal connection termination sequence. If you write to a socket output stream after invoking shutdownOutput() on the socket, the stream will throw an IOException.

exception
IOException if an I/O error occurs when shutting down this socket.
see
java.net.Socket#shutdownInput()
see
java.net.Socket#close()
see
java.net.Socket#setSoLinger(boolean, int)
since
1.3

      throw new IOException("Method not implemented!");
    
protected booleansupportsUrgentData()
Returns whether or not this SocketImpl supports sending urgent data. By default, false is returned unless the method is overridden in a sub-class

return
true if urgent data supported
see
java.net.SocketImpl#address
since
1.4

        return false; // must be overridden in sub-class
    
public java.lang.StringtoString()
Returns the address and port of this socket as a String.

return
a string representation of this socket.

	return "Socket[addr=" + getInetAddress() +
	    ",port=" + getPort() + ",localport=" + getLocalPort()  + "]";