(已完成)java socket-套接字实现类SocketImpl.md

285 阅读1分钟

类继承图

1.接口 2.抽象类 3.实现类

接口SocketImpl

/**

 * The abstract class {@code SocketImpl} is a common superclass

 * of all classes that actually implement sockets. It is used to

 * create both client and server sockets.

 * <p>

 * A "plain" socket implements these methods exactly as

 * described, without attempting to go through a firewall or proxy.

 *

 * @author  unascribed

 * @since   JDK1.0

 */

public abstract class SocketImpl implements SocketOptions {

    /**

     * The actual Socket object.

     */

    Socket socket = null; //客户端套接字

    ServerSocket serverSocket = null; //服务器端套接字



    /**

     * The file descriptor object for this socket.

     */

    protected FileDescriptor fd; //套接字的文件描述符



    /**

     * The IP address of the remote end of this socket.

     */

    protected InetAddress address; //以下是ip地址和端口

 

    /**

     * The port number on the remote host to which this socket is connected.

     */

    protected int port;



    /**

     * The local port number to which this socket is connected.

     */

    protected int localport;


服务器端套接字类

包含了套接字实现类

public

class ServerSocket implements java.io.Closeable {

    /**

     * Various states of this socket.

     */

    private boolean created = false;

    private boolean bound = false;

    private boolean closed = false;

    private Object closeLock = new Object();



    /**

     * The implementation of this Socket.

     */

    private SocketImpl impl; //套接字实现类


客户端套接字类

也包含了套接字实现类

public

class Socket implements java.io.Closeable {

    /**

     * Various states of this socket.

     */

    private boolean created = false;

    private boolean bound = false;

    private boolean connected = false;

    private boolean closed = false;

    private Object closeLock = new Object();

    private boolean shutIn = false;

    private boolean shutOut = false;



    /**

     * The implementation of this Socket.

     */

    SocketImpl impl; //套接字实现类



    /**

     * Are we using an older SocketImpl?

     */

    private boolean oldImpl = false;


套接字实现类-简单套接字实现类

class PlainSocketImpl extends AbstractPlainSocketImpl

{

    private AbstractPlainSocketImpl impl;