1 /* Socket.java -- Client socket implementation
2 Copyright (C) 1998, 1999, 2000, 2002, 2003 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
41 import gnu
.java
.net
.PlainSocketImpl
;
42 import java
.io
.InputStream
;
43 import java
.io
.IOException
;
44 import java
.io
.OutputStream
;
45 import java
.nio
.channels
.SocketChannel
;
46 import java
.nio
.channels
.IllegalBlockingModeException
;
48 /* Written using on-line Java Platform 1.2 API Specification.
49 * Status: I believe all methods are implemented.
53 * This class models a client site socket. A socket is a TCP/IP endpoint
54 * for network communications conceptually similar to a file handle.
56 * This class does not actually do any work. Instead, it redirects all of
57 * its calls to a socket implementation object which implements the
58 * <code>SocketImpl</code> interface. The implementation class is
59 * instantiated by factory class that implements the
60 * <code>SocketImplFactory interface</code>. A default
61 * factory is provided, however the factory may be set by a call to
62 * the <code>setSocketImplFactory</code> method. Note that this may only be
63 * done once per virtual machine. If a subsequent attempt is made to set the
64 * factory, a <code>SocketException</code> will be thrown.
66 * @author Aaron M. Renn (arenn@urbanophile.com)
67 * @author Per Bothner (bothner@cygnus.com)
75 * This is the user SocketImplFactory for this class. If this variable is
76 * null, a default factory is used.
78 static SocketImplFactory factory
;
83 * The implementation object to which calls are redirected
87 private boolean inputShutdown
= false;
88 private boolean outputShutdown
= false;
90 private boolean closed
= false;
93 * Initializes a new instance of <code>Socket</code> object without
94 * connecting to a remote host. This useful for subclasses of socket that
95 * might want this behavior.
97 * @specnote This constructor is public since JDK 1.4
103 impl
= factory
.createSocketImpl();
105 impl
= new PlainSocketImpl();
109 * Initializes a new instance of <code>Socket</code> object without
110 * connecting to a remote host. This is useful for subclasses of socket
111 * that might want this behavior.
113 * Additionally, this socket will be created using the supplied
114 * implementation class instead the default class or one returned by a
115 * factory. If this value is <code>null</code>, the default Socket
116 * implementation is used.
118 * @param impl The <code>SocketImpl</code> to use for this
119 * <code>Socket</code>
121 * @exception SocketException If an error occurs
125 protected Socket (SocketImpl impl
) throws SocketException
128 this.impl
= new PlainSocketImpl();
134 * Initializes a new instance of <code>Socket</code> and connects to the
135 * hostname and port specified as arguments.
137 * @param host The name of the host to connect to
138 * @param port The port number to connect to
140 * @exception UnknownHostException If the hostname cannot be resolved to a
142 * @exception IOException If an error occurs
143 * @exception SecurityException If a security manager exists and its
144 * checkConnect method doesn't allow the operation
146 public Socket (String host
, int port
)
147 throws UnknownHostException
, IOException
149 this(InetAddress
.getByName(host
), port
, null, 0, true);
153 * Initializes a new instance of <code>Socket</code> and connects to the
154 * address and port number specified as arguments.
156 * @param address The address to connect to
157 * @param port The port number to connect to
159 * @exception IOException If an error occurs
160 * @exception SecurityException If a security manager exists and its
161 * checkConnect method doesn't allow the operation
163 public Socket (InetAddress address
, int port
)
166 this(address
, port
, null, 0, true);
170 * Initializes a new instance of <code>Socket</code> that connects to the
171 * named host on the specified port and binds to the specified local address
174 * @param host The name of the remote host to connect to.
175 * @param port The remote port to connect to.
176 * @param loadAddr The local address to bind to.
177 * @param localPort The local port to bind to.
179 * @exception SecurityException If the <code>SecurityManager</code>
180 * exists and does not allow a connection to the specified host/port or
181 * binding to the specified local host/port.
182 * @exception IOException If a connection error occurs.
186 public Socket (String host
, int port
,
187 InetAddress localAddr
, int localPort
) throws IOException
189 this(InetAddress
.getByName(host
), port
, localAddr
, localPort
, true);
193 * Initializes a new instance of <code>Socket</code> and connects to the
194 * address and port number specified as arguments, plus binds to the
195 * specified local address and port.
197 * @param address The remote address to connect to
198 * @param port The remote port to connect to
199 * @param localAddr The local address to connect to
200 * @param localPort The local port to connect to
202 * @exception IOException If an error occurs
203 * @exception SecurityException If a security manager exists and its
204 * checkConnect method doesn't allow the operation
208 public Socket (InetAddress address
, int port
,
209 InetAddress localAddr
, int localPort
) throws IOException
211 this(address
, port
, localAddr
, localPort
, true);
215 * Initializes a new instance of <code>Socket</code> and connects to the
216 * hostname and port specified as arguments. If the stream argument is set
217 * to <code>true</code>, then a stream socket is created. If it is
218 * <code>false</code>, a datagram socket is created.
220 * @param host The name of the host to connect to
221 * @param port The port to connect to
222 * @param stream <code>true</code> for a stream socket, <code>false</code>
223 * for a datagram socket
225 * @exception IOException If an error occurs
226 * @exception SecurityException If a security manager exists and its
227 * checkConnect method doesn't allow the operation
229 * @deprecated Use the <code>DatagramSocket</code> class to create
230 * datagram oriented sockets.
232 public Socket (String host
, int port
, boolean stream
) throws IOException
234 this(InetAddress
.getByName(host
), port
, null, 0, stream
);
238 * Initializes a new instance of <code>Socket</code> and connects to the
239 * address and port number specified as arguments. If the stream param is
240 * <code>true</code>, a stream socket will be created, otherwise a datagram
243 * @param host The address to connect to
244 * @param port The port number to connect to
245 * @param stream <code>true</code> to create a stream socket,
246 * <code>false</code> to create a datagram socket.
248 * @exception IOException If an error occurs
249 * @exception SecurityException If a security manager exists and its
250 * checkConnect method doesn't allow the operation
252 * @deprecated Use the <code>DatagramSocket</code> class to create
253 * datagram oriented sockets.
255 public Socket (InetAddress host
, int port
, boolean stream
) throws IOException
257 this(host
, port
, null, 0, stream
);
261 * This constructor is where the real work takes place. Connect to the
262 * specified address and port. Use default local values if not specified,
263 * otherwise use the local host and port passed in. Create as stream or
264 * datagram based on "stream" argument.
267 * @param raddr The remote address to connect to
268 * @param rport The remote port to connect to
269 * @param laddr The local address to connect to
270 * @param lport The local port to connect to
271 * @param stream true for a stream socket, false for a datagram socket
273 * @exception IOException If an error occurs
274 * @exception SecurityException If a security manager exists and its
275 * checkConnect method doesn't allow the operation
277 private Socket(InetAddress raddr
, int rport
, InetAddress laddr
, int lport
,
278 boolean stream
) throws IOException
282 SecurityManager sm
= System
.getSecurityManager();
284 sm
.checkConnect(raddr
.getHostName(), rport
);
287 SocketAddress bindaddr
=
288 laddr
== null ?
null : new InetSocketAddress (laddr
, lport
);
292 connect (new InetSocketAddress (raddr
, rport
));
294 // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
295 // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
296 // that default. JDK 1.2 doc infers not to do a bind.
300 * Binds the socket to the givent local address/port
302 * @param bindpoint The address/port to bind to
304 * @exception IOException If an error occurs
305 * @exception SecurityException If a security manager exists and its
306 * checkConnect method doesn't allow the operation
307 * @exception IllegalArgumentException If the address type is not supported
311 public void bind (SocketAddress bindpoint
) throws IOException
314 throw new SocketException ("Socket is closed");
316 // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
317 // socket will be bound to an ephemeral port and a valid local address.
318 if (bindpoint
== null)
319 bindpoint
= new InetSocketAddress (InetAddress
.ANY_IF
, 0);
321 if ( !(bindpoint
instanceof InetSocketAddress
))
322 throw new IllegalArgumentException ();
324 InetSocketAddress tmp
= (InetSocketAddress
) bindpoint
;
329 // bind to address/port
332 impl
.bind (tmp
.getAddress(), tmp
.getPort());
334 catch (IOException exception
)
339 catch (RuntimeException exception
)
352 * Connects the socket with a remote address.
354 * @param endpoint The address to connect to
356 * @exception IOException If an error occurs
357 * @exception IllegalArgumentException If the addess type is not supported
358 * @exception IllegalBlockingModeException If this socket has an associated
359 * channel, and the channel is in non-blocking mode
363 public void connect (SocketAddress endpoint
)
366 connect (endpoint
, 0);
370 * Connects the socket with a remote address. A timeout of zero is
371 * interpreted as an infinite timeout. The connection will then block
372 * until established or an error occurs.
374 * @param endpoint The address to connect to
376 * @exception IOException If an error occurs
377 * @exception IllegalArgumentException If the address type is not supported
378 * @exception IllegalBlockingModeException If this socket has an associated
379 * channel, and the channel is in non-blocking mode
380 * @exception SocketTimeoutException If the timeout is reached
384 public void connect (SocketAddress endpoint
, int timeout
)
388 throw new SocketException ("Socket is closed");
390 if (! (endpoint
instanceof InetSocketAddress
))
391 throw new IllegalArgumentException ("Address type not supported");
393 if (getChannel() != null
394 && !getChannel().isBlocking ())
395 throw new IllegalBlockingModeException ();
402 impl
.connect (endpoint
, timeout
);
404 catch (IOException exception
)
409 catch (RuntimeException exception
)
422 * Returns the address of the remote end of the socket. If this socket
423 * is not connected, then <code>null</code> is returned.
425 * @return The remote address this socket is connected to
427 public InetAddress
getInetAddress ()
429 return impl
.getInetAddress();
433 * Returns the local address to which this socket is bound. If this socket
434 * is not connected, then <code>null</code> is returned.
436 * @return The local address
440 public InetAddress
getLocalAddress ()
442 InetAddress addr
= null;
445 addr
= (InetAddress
)impl
.getOption(SocketOptions
.SO_BINDADDR
);
447 catch(SocketException e
)
449 // (hopefully) shouldn't happen
450 // throw new java.lang.InternalError
451 // ("Error in PlainSocketImpl.getOption");
455 // FIXME: According to libgcj, checkConnect() is supposed to be called
456 // before performing this operation. Problems: 1) We don't have the
457 // addr until after we do it, so we do a post check. 2). The docs I
458 // see don't require this in the Socket case, only DatagramSocket, but
459 // we'll assume they mean both.
460 SecurityManager sm
= System
.getSecurityManager();
462 sm
.checkConnect(addr
.getHostName(), getLocalPort());
468 * Returns the port number of the remote end of the socket connection. If
469 * this socket is not connected, then -1 is returned.
471 * @return The remote port this socket is connected to
473 public int getPort ()
476 return impl
.getPort();
482 * Returns the local port number to which this socket is bound. If this
483 * socket is not connected, then -1 is returned.
485 * @return The local port
487 public int getLocalPort ()
490 return impl
.getLocalPort();
496 * If the socket is already bound this returns the local SocketAddress,
501 public SocketAddress
getLocalSocketAddress()
503 InetAddress addr
= getLocalAddress ();
508 return new InetSocketAddress (addr
, impl
.getLocalPort());
512 * If the socket is already connected this returns the remote SocketAddress,
517 public SocketAddress
getRemoteSocketAddress()
522 return new InetSocketAddress (impl
.getInetAddress (), impl
.getPort ());
526 * Returns an InputStream for reading from this socket.
528 * @return The InputStream object
530 * @exception IOException If an error occurs or Socket is not connected
532 public InputStream
getInputStream () throws IOException
535 return(impl
.getInputStream());
537 throw new IOException("Not connected");
541 * Returns an OutputStream for writing to this socket.
543 * @return The OutputStream object
545 * @exception IOException If an error occurs or Socket is not connected
547 public OutputStream
getOutputStream () throws IOException
550 return impl
.getOutputStream();
552 throw new IOException("Not connected");
556 * Sets the TCP_NODELAY option on the socket.
558 * @param on true to enable, false to disable
560 * @exception SocketException If an error occurs or Socket is not connected
564 public void setTcpNoDelay (boolean on
) throws SocketException
566 impl
.setOption(SocketOptions
.TCP_NODELAY
, new Boolean(on
));
570 * Tests whether or not the TCP_NODELAY option is set on the socket.
571 * Returns true if enabled, false if disabled. When on it disables the
572 * Nagle algorithm which means that packets are always send immediatly and
573 * never merged together to reduce network trafic.
575 * @return Whether or not TCP_NODELAY is set
577 * @exception SocketException If an error occurs or Socket not connected
581 public boolean getTcpNoDelay() throws SocketException
583 Object on
= impl
.getOption(SocketOptions
.TCP_NODELAY
);
585 if (on
instanceof Boolean
)
586 return(((Boolean
)on
).booleanValue());
588 throw new SocketException("Internal Error");
592 * Sets the value of the SO_LINGER option on the socket. If the
593 * SO_LINGER option is set on a socket and there is still data waiting to
594 * be sent when the socket is closed, then the close operation will block
595 * until either that data is delivered or until the timeout period
596 * expires. The linger interval is specified in hundreths of a second
597 * (platform specific?)
599 * @param on true to enable SO_LINGER, false to disable
600 * @param linger The SO_LINGER timeout in hundreths of a second or -1 if
603 * @exception SocketException If an error occurs or Socket not connected
604 * @exception IllegalArgumentException If linger is negative
608 public void setSoLinger(boolean on
, int linger
) throws SocketException
613 throw new IllegalArgumentException("SO_LINGER must be >= 0");
618 impl
.setOption(SocketOptions
.SO_LINGER
, new Integer(linger
));
622 impl
.setOption(SocketOptions
.SO_LINGER
, new Boolean(false));
627 * Returns the value of the SO_LINGER option on the socket. If the
628 * SO_LINGER option is set on a socket and there is still data waiting to
629 * be sent when the socket is closed, then the close operation will block
630 * until either that data is delivered or until the timeout period
631 * expires. This method either returns the timeouts (in hundredths of
632 * of a second (platform specific?)) if SO_LINGER is set, or -1 if
633 * SO_LINGER is not set.
635 * @return The SO_LINGER timeout in hundreths of a second or -1
636 * if SO_LINGER not set
638 * @exception SocketException If an error occurs or Socket is not connected
642 public int getSoLinger() throws SocketException
644 Object linger
= impl
.getOption(SocketOptions
.SO_LINGER
);
645 if (linger
instanceof Integer
)
646 return(((Integer
)linger
).intValue());
652 * Sends urgent data through the socket
654 * @param data The data to send.
655 * Only the lowest eight bits of data are sent
657 * @exception IOException If an error occurs
661 public void sendUrgentData (int data
) throws IOException
663 impl
.sendUrgentData (data
);
667 * Enables/disables the SO_OOBINLINE option
669 * @param on True if SO_OOBLINE should be enabled
671 * @exception SocketException If an error occurs
675 public void setOOBInline (boolean on
) throws SocketException
677 impl
.setOption(SocketOptions
.SO_OOBINLINE
, new Boolean(on
));
681 * Returns the current setting of the SO_OOBINLINE option for this socket
683 * @exception SocketException If an error occurs
687 public boolean getOOBInline () throws SocketException
689 Object buf
= impl
.getOption(SocketOptions
.SO_OOBINLINE
);
691 if (buf
instanceof Boolean
)
692 return(((Boolean
)buf
).booleanValue());
694 throw new SocketException("Internal Error: Unexpected type");
698 * Sets the value of the SO_TIMEOUT option on the socket. If this value
699 * is set, and an read/write is performed that does not complete within
700 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
701 * would be sent in Unix if no data had been read). A value of 0 for
702 * this option implies that there is no timeout (ie, operations will
703 * block forever). On systems that have separate read and write timeout
704 * values, this method returns the read timeout. This
705 * value is in milliseconds.
707 * @param timeout The length of the timeout in milliseconds, or
708 * 0 to indicate no timeout.
710 * @exception SocketException If an error occurs or Socket not connected
714 public synchronized void setSoTimeout (int timeout
) throws SocketException
717 throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
719 impl
.setOption(SocketOptions
.SO_TIMEOUT
, new Integer(timeout
));
723 * Returns the value of the SO_TIMEOUT option on the socket. If this value
724 * is set, and an read/write is performed that does not complete within
725 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
726 * would be sent in Unix if no data had been read). A value of 0 for
727 * this option implies that there is no timeout (ie, operations will
728 * block forever). On systems that have separate read and write timeout
729 * values, this method returns the read timeout. This
730 * value is in thousandths of a second (implementation specific?).
732 * @return The length of the timeout in thousandth's of a second or 0
735 * @exception SocketException If an error occurs or Socket not connected
739 public synchronized int getSoTimeout () throws SocketException
741 Object timeout
= impl
.getOption(SocketOptions
.SO_TIMEOUT
);
742 if (timeout
instanceof Integer
)
743 return(((Integer
)timeout
).intValue());
749 * This method sets the value for the system level socket option
750 * SO_SNDBUF to the specified value. Note that valid values for this
751 * option are specific to a given operating system.
753 * @param size The new send buffer size.
755 * @exception SocketException If an error occurs or Socket not connected
756 * @exception IllegalArgumentException If size is 0 or negative
760 public void setSendBufferSize (int size
) throws SocketException
763 throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
765 impl
.setOption(SocketOptions
.SO_SNDBUF
, new Integer(size
));
769 * This method returns the value of the system level socket option
770 * SO_SNDBUF, which is used by the operating system to tune buffer
771 * sizes for data transfers.
773 * @return The send buffer size.
775 * @exception SocketException If an error occurs or socket not connected
779 public int getSendBufferSize () throws SocketException
781 Object buf
= impl
.getOption(SocketOptions
.SO_SNDBUF
);
783 if (buf
instanceof Integer
)
784 return(((Integer
)buf
).intValue());
786 throw new SocketException("Internal Error: Unexpected type");
790 * This method sets the value for the system level socket option
791 * SO_RCVBUF to the specified value. Note that valid values for this
792 * option are specific to a given operating system.
794 * @param size The new receive buffer size.
796 * @exception SocketException If an error occurs or Socket is not connected
797 * @exception IllegalArgumentException If size is 0 or negative
801 public void setReceiveBufferSize (int size
) throws SocketException
804 throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
806 impl
.setOption(SocketOptions
.SO_RCVBUF
, new Integer(size
));
810 * This method returns the value of the system level socket option
811 * SO_RCVBUF, which is used by the operating system to tune buffer
812 * sizes for data transfers.
814 * @return The receive buffer size.
816 * @exception SocketException If an error occurs or Socket is not connected
820 public int getReceiveBufferSize () throws SocketException
822 Object buf
= impl
.getOption(SocketOptions
.SO_RCVBUF
);
824 if (buf
instanceof Integer
)
825 return(((Integer
)buf
).intValue());
827 throw new SocketException("Internal Error: Unexpected type");
831 * This method sets the value for the socket level socket option
834 * @param on True if SO_KEEPALIVE should be enabled
836 * @exception SocketException If an error occurs or Socket is not connected
840 public void setKeepAlive (boolean on
) throws SocketException
842 impl
.setOption(SocketOptions
.SO_KEEPALIVE
, new Boolean(on
));
846 * This method returns the value of the socket level socket option
849 * @return The setting
851 * @exception SocketException If an error occurs or Socket is not connected
855 public boolean getKeepAlive () throws SocketException
857 Object buf
= impl
.getOption(SocketOptions
.SO_KEEPALIVE
);
859 if (buf
instanceof Boolean
)
860 return(((Boolean
)buf
).booleanValue());
862 throw new SocketException("Internal Error: Unexpected type");
868 * @exception IOException If an error occurs
870 public synchronized void close () throws IOException
875 if (getChannel() != null)
876 getChannel().close();
882 * Converts this <code>Socket</code> to a <code>String</code>.
884 * @return The <code>String</code> representation of this <code>Socket</code>
886 public String
toString ()
888 return("Socket " + impl
);
894 * Sets the <code>SocketImplFactory</code>. This may be done only once per
895 * virtual machine. Subsequent attempts will generate a
896 * <code>SocketException</code>. Note that a <code>SecurityManager</code>
897 * check is made prior to setting the factory. If
898 * insufficient privileges exist to set the factory, then an
899 * <code>IOException</code> will be thrown.
901 * @exception SecurityException If the <code>SecurityManager</code> does
902 * not allow this operation.
903 * @exception SocketException If the SocketImplFactory is already defined
904 * @exception IOException If any other error occurs
906 public static synchronized void setSocketImplFactory (SocketImplFactory fac
)
909 // See if already set
911 throw new SocketException("SocketImplFactory already defined");
914 SecurityManager sm
= System
.getSecurityManager();
916 sm
.checkSetFactory();
919 throw new SocketException("SocketImplFactory cannot be null");
925 * Closes the input side of the socket stream.
927 * @exception IOException If an error occurs.
931 public void shutdownInput() throws IOException
934 impl
.shutdownInput();
936 inputShutdown
= true;
940 * Closes the output side of the socket stream.
942 * @exception IOException If an error occurs.
946 public void shutdownOutput() throws IOException
949 impl
.shutdownOutput();
951 outputShutdown
= true;
955 * Returns the socket channel associated with this socket.
957 * It returns null if no associated socket exists.
961 public SocketChannel
getChannel()
967 * Checks if the SO_REUSEADDR option is enabled
969 * @exception SocketException If an error occurs
973 public boolean getReuseAddress () throws SocketException
975 Object reuseaddr
= impl
.getOption (SocketOptions
.SO_REUSEADDR
);
977 if (!(reuseaddr
instanceof Boolean
))
978 throw new SocketException ("Internal Error");
980 return ((Boolean
) reuseaddr
).booleanValue ();
984 * Enables/Disables the SO_REUSEADDR option
986 * @exception SocketException If an error occurs
990 public void setReuseAddress (boolean on
) throws SocketException
992 impl
.setOption (SocketOptions
.SO_REUSEADDR
, new Boolean (on
));
996 * Returns the current traffic class
998 * @exception SocketException If an error occurs
1000 * @see Socket#setTrafficClass(int tc)
1004 public int getTrafficClass () throws SocketException
1006 Object obj
= impl
.getOption(SocketOptions
.IP_TOS
);
1008 if (obj
instanceof Integer
)
1009 return ((Integer
) obj
).intValue ();
1011 throw new SocketException ("Unexpected type");
1015 * Sets the traffic class value
1017 * @param tc The traffic class
1019 * @exception SocketException If an error occurs
1020 * @exception IllegalArgumentException If tc value is illegal
1022 * @see Socket#getTrafficClass()
1026 public void setTrafficClass (int tc
) throws SocketException
1028 if (tc
< 0 || tc
> 255)
1029 throw new IllegalArgumentException();
1031 impl
.setOption (SocketOptions
.IP_TOS
, new Integer (tc
));
1035 * Checks if the socket is connected
1039 public boolean isConnected ()
1041 return impl
.getInetAddress () != null;
1045 * Checks if the socket is already bound.
1049 public boolean isBound ()
1051 return getLocalAddress () != null;
1055 * Checks if the socket is closed.
1059 public boolean isClosed ()
1065 * Checks if the socket's input stream is shutdown
1069 public boolean isInputShutdown ()
1071 return inputShutdown
;
1075 * Checks if the socket's output stream is shutdown
1079 public boolean isOutputShutdown ()
1081 return outputShutdown
;