home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1997 May / Pcwk0597.iso / sybase / starbuck / java.z / SocketImpl.java < prev    next >
Text File  |  1996-05-03  |  4KB  |  139 lines

  1. /*
  2.  * @(#)SocketImpl.java    1.17 96/04/01 Jonathan Payne
  3.  *
  4.  * Copyright (c) 1994 Sun Microsystems, Inc. All Rights Reserved.
  5.  *
  6.  * Permission to use, copy, modify, and distribute this software
  7.  * and its documentation for NON-COMMERCIAL purposes and without
  8.  * fee is hereby granted provided that this copyright notice
  9.  * appears in all copies. Please refer to the file "copyright.html"
  10.  * for further important copyright and licensing information.
  11.  *
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  13.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  14.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  15.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  16.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  17.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  18.  */
  19.  
  20. package java.net;
  21.  
  22. import java.io.IOException;
  23. import java.io.InputStream;
  24. import java.io.OutputStream;
  25. import java.io.FileDescriptor;
  26.  
  27. /**
  28.  * This is the Socket implementation class. It is an
  29.  * abstract class that must be subclassed to provide
  30.  * an actual implementation.
  31.  *
  32.  * @version     1.17, 01 Apr 1996
  33.  * @author     Jonathan Payne
  34.  * @author     Arthur van Hoff
  35.  */
  36. public abstract class SocketImpl {
  37.  
  38.     /**
  39.      * The file descriptor object
  40.      */
  41.     protected FileDescriptor fd;
  42.     
  43.     /**
  44.      * The internet address where the socket will make a connection.
  45.      */
  46.     protected InetAddress address;
  47.    
  48.     /**
  49.      * The port where the socket will make a connection.
  50.      */
  51.     protected int port;
  52.     protected int localport;   
  53.  
  54.     /**
  55.      * Creates a socket with a boolean that specifies whether this
  56.      * is a stream socket or a datagram socket.
  57.      * @param stream a boolean indicating whether this is a stream
  58.      * or datagram socket
  59.      */
  60.     protected abstract void create(boolean stream) throws IOException;
  61.  
  62.     /**
  63.      * Connects the socket to the specified port on the specified host.
  64.      * @param host the specified host of the connection
  65.      * @param port the port where the connection is made
  66.      */
  67.     protected abstract void connect(String host, int port) throws IOException;
  68.  
  69.     /**
  70.      * Connects the socket to the specified address on the specified
  71.      * port.
  72.      * @param address the specified address of the connection
  73.      * @param port the specified port where connection is made
  74.      */
  75.     protected abstract void connect(InetAddress address, int port) throws IOException;
  76.  
  77.     /**
  78.      * Binds the socket to the specified port on the specified host.
  79.      * @param host the host
  80.      * @param port the port   
  81.      */
  82.     protected abstract void bind(InetAddress host, int port) throws IOException;
  83.  
  84.     /**
  85.      * Specify to the system how many connection requests the system
  86.      * will queue up while waiting for the SocketImpl to execute accept().
  87.      *
  88.      * @param backlog the number of queued connect requests pending accept
  89.      */
  90.     protected abstract void listen(int backlog) throws IOException;
  91.  
  92.     /**
  93.      * Accepts a connection.
  94.      * @param s the accepted connection
  95.      */
  96.     protected abstract void accept(SocketImpl s) throws IOException;
  97.  
  98.     /**
  99.      * Gets an InputStream for this socket.
  100.      */
  101.     protected abstract InputStream getInputStream() throws IOException;
  102.  
  103.     /**
  104.      * Gets an OutputStream for this socket.
  105.      */
  106.     protected abstract OutputStream getOutputStream() throws IOException;
  107.  
  108.     /**
  109.      * Returns the number of bytes that can be read without blocking.
  110.      */
  111.     protected abstract int available() throws IOException;
  112.  
  113.     /**
  114.      * Closes the socket.
  115.      */
  116.     protected abstract void close() throws IOException;
  117.  
  118.     protected FileDescriptor getFileDescriptor() {
  119.     return fd;
  120.     }
  121.     protected InetAddress getInetAddress() {
  122.     return address;
  123.     }
  124.     protected int getPort() {
  125.     return port;
  126.     }
  127.     protected int getLocalPort() {
  128.     return localport;
  129.     }
  130.     
  131.     /**
  132.      * Returns the address and port of this Socket as a String.
  133.      */
  134.     public String toString() {
  135.     return "Socket[addr=" + getInetAddress() +
  136.         ",port=" + getPort() + ",localport=" + getLocalPort()  + "]";
  137.     }
  138. }
  139.