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 SocketChannel ch
; // this field must have been set if created by SocketChannel
92 private boolean closed
= false;
95 * Initializes a new instance of <code>Socket</code> object without
96 * connecting to a remote host. This useful for subclasses of socket that
97 * might want this behavior.
99 * @specnote This constructor is public since JDK 1.4
105 impl
= factory
.createSocketImpl();
107 impl
= new PlainSocketImpl();
111 * Initializes a new instance of <code>Socket</code> object without
112 * connecting to a remote host. This is useful for subclasses of socket
113 * that might want this behavior.
115 * Additionally, this socket will be created using the supplied
116 * implementation class instead the default class or one returned by a
117 * factory. If this value is <code>null</code>, the default Socket
118 * implementation is used.
120 * @param impl The <code>SocketImpl</code> to use for this
121 * <code>Socket</code>
123 * @exception SocketException If an error occurs
127 protected Socket (SocketImpl impl
) throws SocketException
130 this.impl
= new PlainSocketImpl();
136 * Initializes a new instance of <code>Socket</code> and connects to the
137 * hostname and port specified as arguments.
139 * @param host The name of the host to connect to
140 * @param port The port number to connect to
142 * @exception UnknownHostException If the hostname cannot be resolved to a
144 * @exception IOException If an error occurs
145 * @exception SecurityException If a security manager exists and its
146 * checkConnect method doesn't allow the operation
148 public Socket (String host
, int port
)
149 throws UnknownHostException
, IOException
151 this(InetAddress
.getByName(host
), port
, null, 0, true);
155 * Initializes a new instance of <code>Socket</code> and connects to the
156 * address and port number specified as arguments.
158 * @param address The address to connect to
159 * @param port The port number to connect to
161 * @exception IOException If an error occurs
162 * @exception SecurityException If a security manager exists and its
163 * checkConnect method doesn't allow the operation
165 public Socket (InetAddress address
, int port
)
168 this(address
, port
, null, 0, true);
172 * Initializes a new instance of <code>Socket</code> that connects to the
173 * named host on the specified port and binds to the specified local address
176 * @param host The name of the remote host to connect to.
177 * @param port The remote port to connect to.
178 * @param loadAddr The local address to bind to.
179 * @param localPort The local port to bind to.
181 * @exception SecurityException If the <code>SecurityManager</code>
182 * exists and does not allow a connection to the specified host/port or
183 * binding to the specified local host/port.
184 * @exception IOException If a connection error occurs.
188 public Socket (String host
, int port
,
189 InetAddress localAddr
, int localPort
) throws IOException
191 this(InetAddress
.getByName(host
), port
, localAddr
, localPort
, true);
195 * Initializes a new instance of <code>Socket</code> and connects to the
196 * address and port number specified as arguments, plus binds to the
197 * specified local address and port.
199 * @param address The remote address to connect to
200 * @param port The remote port to connect to
201 * @param localAddr The local address to connect to
202 * @param localPort The local port to connect to
204 * @exception IOException If an error occurs
205 * @exception SecurityException If a security manager exists and its
206 * checkConnect method doesn't allow the operation
210 public Socket (InetAddress address
, int port
,
211 InetAddress localAddr
, int localPort
) throws IOException
213 this(address
, port
, localAddr
, localPort
, true);
217 * Initializes a new instance of <code>Socket</code> and connects to the
218 * hostname and port specified as arguments. If the stream argument is set
219 * to <code>true</code>, then a stream socket is created. If it is
220 * <code>false</code>, a datagram socket is created.
222 * @param host The name of the host to connect to
223 * @param port The port to connect to
224 * @param stream <code>true</code> for a stream socket, <code>false</code>
225 * for a datagram socket
227 * @exception IOException If an error occurs
228 * @exception SecurityException If a security manager exists and its
229 * checkConnect method doesn't allow the operation
231 * @deprecated Use the <code>DatagramSocket</code> class to create
232 * datagram oriented sockets.
234 public Socket (String host
, int port
, boolean stream
) throws IOException
236 this(InetAddress
.getByName(host
), port
, null, 0, stream
);
240 * Initializes a new instance of <code>Socket</code> and connects to the
241 * address and port number specified as arguments. If the stream param is
242 * <code>true</code>, a stream socket will be created, otherwise a datagram
245 * @param host The address to connect to
246 * @param port The port number to connect to
247 * @param stream <code>true</code> to create a stream socket,
248 * <code>false</code> to create a datagram socket.
250 * @exception IOException If an error occurs
251 * @exception SecurityException If a security manager exists and its
252 * checkConnect method doesn't allow the operation
254 * @deprecated Use the <code>DatagramSocket</code> class to create
255 * datagram oriented sockets.
257 public Socket (InetAddress host
, int port
, boolean stream
) throws IOException
259 this(host
, port
, null, 0, stream
);
263 * This constructor is where the real work takes place. Connect to the
264 * specified address and port. Use default local values if not specified,
265 * otherwise use the local host and port passed in. Create as stream or
266 * datagram based on "stream" argument.
269 * @param raddr The remote address to connect to
270 * @param rport The remote port to connect to
271 * @param laddr The local address to connect to
272 * @param lport The local port to connect to
273 * @param stream true for a stream socket, false for a datagram socket
275 * @exception IOException If an error occurs
276 * @exception SecurityException If a security manager exists and its
277 * checkConnect method doesn't allow the operation
279 private Socket(InetAddress raddr
, int rport
, InetAddress laddr
, int lport
,
280 boolean stream
) throws IOException
284 SecurityManager sm
= System
.getSecurityManager();
286 sm
.checkConnect(raddr
.getHostName(), rport
);
289 SocketAddress bindaddr
=
290 laddr
== null ?
null : new InetSocketAddress (laddr
, lport
);
294 connect (new InetSocketAddress (raddr
, rport
));
296 // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
297 // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
298 // that default. JDK 1.2 doc infers not to do a bind.
302 * This method may only be used by java.nio.channels.ServerSocketChannel.accept and
303 * java.nio.channels.SocketChannel.open.
305 void setChannel (SocketChannel ch
)
311 * Binds the socket to the givent local address/port
313 * @param bindpoint The address/port to bind to
315 * @exception IOException If an error occurs
316 * @exception SecurityException If a security manager exists and its
317 * checkConnect method doesn't allow the operation
318 * @exception IllegalArgumentException If the address type is not supported
322 public void bind (SocketAddress bindpoint
) throws IOException
325 throw new SocketException ("Socket is closed");
327 // XXX: JDK 1.4.1 API documentation says that if bindpoint is null the
328 // socket will be bound to an ephemeral port and a valid local address.
329 if (bindpoint
== null)
330 bindpoint
= new InetSocketAddress (InetAddress
.ANY_IF
, 0);
332 if ( !(bindpoint
instanceof InetSocketAddress
))
333 throw new IllegalArgumentException ();
335 InetSocketAddress tmp
= (InetSocketAddress
) bindpoint
;
340 // bind to address/port
343 impl
.bind (tmp
.getAddress(), tmp
.getPort());
345 catch (IOException exception
)
350 catch (RuntimeException exception
)
363 * Connects the socket with a remote address.
365 * @param endpoint The address to connect to
367 * @exception IOException If an error occurs
368 * @exception IllegalArgumentException If the addess type is not supported
369 * @exception IllegalBlockingModeException If this socket has an associated
370 * channel, and the channel is in non-blocking mode
374 public void connect (SocketAddress endpoint
)
377 connect (endpoint
, 0);
381 * Connects the socket with a remote address. A timeout of zero is
382 * interpreted as an infinite timeout. The connection will then block
383 * until established or an error occurs.
385 * @param endpoint The address to connect to
387 * @exception IOException If an error occurs
388 * @exception IllegalArgumentException If the address type is not supported
389 * @exception IllegalBlockingModeException If this socket has an associated
390 * channel, and the channel is in non-blocking mode
391 * @exception SocketTimeoutException If the timeout is reached
395 public void connect (SocketAddress endpoint
, int timeout
)
399 throw new SocketException ("Socket is closed");
401 if (! (endpoint
instanceof InetSocketAddress
))
402 throw new IllegalArgumentException ("Address type not supported");
404 if (ch
!= null && !ch
.isBlocking ())
405 throw new IllegalBlockingModeException ();
412 impl
.connect (endpoint
, timeout
);
414 catch (IOException exception
)
419 catch (RuntimeException exception
)
432 * Returns the address of the remote end of the socket. If this socket
433 * is not connected, then <code>null</code> is returned.
435 * @return The remote address this socket is connected to
437 public InetAddress
getInetAddress ()
439 return impl
.getInetAddress();
443 * Returns the local address to which this socket is bound. If this socket
444 * is not connected, then <code>null</code> is returned.
446 * @return The local address
450 public InetAddress
getLocalAddress ()
452 InetAddress addr
= null;
455 addr
= (InetAddress
)impl
.getOption(SocketOptions
.SO_BINDADDR
);
457 catch(SocketException e
)
459 // (hopefully) shouldn't happen
460 // throw new java.lang.InternalError
461 // ("Error in PlainSocketImpl.getOption");
465 // FIXME: According to libgcj, checkConnect() is supposed to be called
466 // before performing this operation. Problems: 1) We don't have the
467 // addr until after we do it, so we do a post check. 2). The docs I
468 // see don't require this in the Socket case, only DatagramSocket, but
469 // we'll assume they mean both.
470 SecurityManager sm
= System
.getSecurityManager();
472 sm
.checkConnect(addr
.getHostName(), getLocalPort());
478 * Returns the port number of the remote end of the socket connection. If
479 * this socket is not connected, then -1 is returned.
481 * @return The remote port this socket is connected to
483 public int getPort ()
486 return impl
.getPort();
492 * Returns the local port number to which this socket is bound. If this
493 * socket is not connected, then -1 is returned.
495 * @return The local port
497 public int getLocalPort ()
500 return impl
.getLocalPort();
506 * If the socket is already bound this returns the local SocketAddress,
511 public SocketAddress
getLocalSocketAddress()
513 InetAddress addr
= getLocalAddress ();
518 return new InetSocketAddress (addr
, impl
.getLocalPort());
522 * If the socket is already connected this returns the remote SocketAddress,
527 public SocketAddress
getRemoteSocketAddress()
532 return new InetSocketAddress (impl
.getInetAddress (), impl
.getPort ());
536 * Returns an InputStream for reading from this socket.
538 * @return The InputStream object
540 * @exception IOException If an error occurs or Socket is not connected
542 public InputStream
getInputStream () throws IOException
545 return(impl
.getInputStream());
547 throw new IOException("Not connected");
551 * Returns an OutputStream for writing to this socket.
553 * @return The OutputStream object
555 * @exception IOException If an error occurs or Socket is not connected
557 public OutputStream
getOutputStream () throws IOException
560 return impl
.getOutputStream();
562 throw new IOException("Not connected");
566 * Sets the TCP_NODELAY option on the socket.
568 * @param on true to enable, false to disable
570 * @exception SocketException If an error occurs or Socket is not connected
574 public void setTcpNoDelay (boolean on
) throws SocketException
576 impl
.setOption(SocketOptions
.TCP_NODELAY
, new Boolean(on
));
580 * Tests whether or not the TCP_NODELAY option is set on the socket.
581 * Returns true if enabled, false if disabled. When on it disables the
582 * Nagle algorithm which means that packets are always send immediatly and
583 * never merged together to reduce network trafic.
585 * @return Whether or not TCP_NODELAY is set
587 * @exception SocketException If an error occurs or Socket not connected
591 public boolean getTcpNoDelay() throws SocketException
593 Object on
= impl
.getOption(SocketOptions
.TCP_NODELAY
);
595 if (on
instanceof Boolean
)
596 return(((Boolean
)on
).booleanValue());
598 throw new SocketException("Internal Error");
602 * Sets the value of the SO_LINGER option on the socket. If the
603 * SO_LINGER option is set on a socket and there is still data waiting to
604 * be sent when the socket is closed, then the close operation will block
605 * until either that data is delivered or until the timeout period
606 * expires. The linger interval is specified in hundreths of a second
607 * (platform specific?)
609 * @param on true to enable SO_LINGER, false to disable
610 * @param linger The SO_LINGER timeout in hundreths of a second or -1 if
613 * @exception SocketException If an error occurs or Socket not connected
614 * @exception IllegalArgumentException If linger is negative
618 public void setSoLinger(boolean on
, int linger
) throws SocketException
623 throw new IllegalArgumentException("SO_LINGER must be >= 0");
628 impl
.setOption(SocketOptions
.SO_LINGER
, new Integer(linger
));
632 impl
.setOption(SocketOptions
.SO_LINGER
, new Boolean(false));
637 * Returns the value of the SO_LINGER option on the socket. If the
638 * SO_LINGER option is set on a socket and there is still data waiting to
639 * be sent when the socket is closed, then the close operation will block
640 * until either that data is delivered or until the timeout period
641 * expires. This method either returns the timeouts (in hundredths of
642 * of a second (platform specific?)) if SO_LINGER is set, or -1 if
643 * SO_LINGER is not set.
645 * @return The SO_LINGER timeout in hundreths of a second or -1
646 * if SO_LINGER not set
648 * @exception SocketException If an error occurs or Socket is not connected
652 public int getSoLinger() throws SocketException
654 Object linger
= impl
.getOption(SocketOptions
.SO_LINGER
);
655 if (linger
instanceof Integer
)
656 return(((Integer
)linger
).intValue());
662 * Sends urgent data through the socket
664 * @param data The data to send.
665 * Only the lowest eight bits of data are sent
667 * @exception IOException If an error occurs
671 public void sendUrgentData (int data
) throws IOException
673 impl
.sendUrgentData (data
);
677 * Enables/disables the SO_OOBINLINE option
679 * @param on True if SO_OOBLINE should be enabled
681 * @exception SocketException If an error occurs
685 public void setOOBInline (boolean on
) throws SocketException
687 impl
.setOption(SocketOptions
.SO_OOBINLINE
, new Boolean(on
));
691 * Returns the current setting of the SO_OOBINLINE option for this socket
693 * @exception SocketException If an error occurs
697 public boolean getOOBInline () throws SocketException
699 Object buf
= impl
.getOption(SocketOptions
.SO_OOBINLINE
);
701 if (buf
instanceof Boolean
)
702 return(((Boolean
)buf
).booleanValue());
704 throw new SocketException("Internal Error: Unexpected type");
708 * Sets the value of the SO_TIMEOUT option on the socket. If this value
709 * is set, and an read/write is performed that does not complete within
710 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
711 * would be sent in Unix if no data had been read). A value of 0 for
712 * this option implies that there is no timeout (ie, operations will
713 * block forever). On systems that have separate read and write timeout
714 * values, this method returns the read timeout. This
715 * value is in milliseconds.
717 * @param timeout The length of the timeout in milliseconds, or
718 * 0 to indicate no timeout.
720 * @exception SocketException If an error occurs or Socket not connected
724 public synchronized void setSoTimeout (int timeout
) throws SocketException
727 throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
729 impl
.setOption(SocketOptions
.SO_TIMEOUT
, new Integer(timeout
));
733 * Returns the value of the SO_TIMEOUT option on the socket. If this value
734 * is set, and an read/write is performed that does not complete within
735 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
736 * would be sent in Unix if no data had been read). A value of 0 for
737 * this option implies that there is no timeout (ie, operations will
738 * block forever). On systems that have separate read and write timeout
739 * values, this method returns the read timeout. This
740 * value is in thousandths of a second (implementation specific?).
742 * @return The length of the timeout in thousandth's of a second or 0
745 * @exception SocketException If an error occurs or Socket not connected
749 public synchronized int getSoTimeout () throws SocketException
751 Object timeout
= impl
.getOption(SocketOptions
.SO_TIMEOUT
);
752 if (timeout
instanceof Integer
)
753 return(((Integer
)timeout
).intValue());
759 * This method sets the value for the system level socket option
760 * SO_SNDBUF to the specified value. Note that valid values for this
761 * option are specific to a given operating system.
763 * @param size The new send buffer size.
765 * @exception SocketException If an error occurs or Socket not connected
766 * @exception IllegalArgumentException If size is 0 or negative
770 public void setSendBufferSize (int size
) throws SocketException
773 throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
775 impl
.setOption(SocketOptions
.SO_SNDBUF
, new Integer(size
));
779 * This method returns the value of the system level socket option
780 * SO_SNDBUF, which is used by the operating system to tune buffer
781 * sizes for data transfers.
783 * @return The send buffer size.
785 * @exception SocketException If an error occurs or socket not connected
789 public int getSendBufferSize () throws SocketException
791 Object buf
= impl
.getOption(SocketOptions
.SO_SNDBUF
);
793 if (buf
instanceof Integer
)
794 return(((Integer
)buf
).intValue());
796 throw new SocketException("Internal Error: Unexpected type");
800 * This method sets the value for the system level socket option
801 * SO_RCVBUF to the specified value. Note that valid values for this
802 * option are specific to a given operating system.
804 * @param size The new receive buffer size.
806 * @exception SocketException If an error occurs or Socket is not connected
807 * @exception IllegalArgumentException If size is 0 or negative
811 public void setReceiveBufferSize (int size
) throws SocketException
814 throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
816 impl
.setOption(SocketOptions
.SO_RCVBUF
, new Integer(size
));
820 * This method returns the value of the system level socket option
821 * SO_RCVBUF, which is used by the operating system to tune buffer
822 * sizes for data transfers.
824 * @return The receive buffer size.
826 * @exception SocketException If an error occurs or Socket is not connected
830 public int getReceiveBufferSize () throws SocketException
832 Object buf
= impl
.getOption(SocketOptions
.SO_RCVBUF
);
834 if (buf
instanceof Integer
)
835 return(((Integer
)buf
).intValue());
837 throw new SocketException("Internal Error: Unexpected type");
841 * This method sets the value for the socket level socket option
844 * @param on True if SO_KEEPALIVE should be enabled
846 * @exception SocketException If an error occurs or Socket is not connected
850 public void setKeepAlive (boolean on
) throws SocketException
852 impl
.setOption(SocketOptions
.SO_KEEPALIVE
, new Boolean(on
));
856 * This method returns the value of the socket level socket option
859 * @return The setting
861 * @exception SocketException If an error occurs or Socket is not connected
865 public boolean getKeepAlive () throws SocketException
867 Object buf
= impl
.getOption(SocketOptions
.SO_KEEPALIVE
);
869 if (buf
instanceof Boolean
)
870 return(((Boolean
)buf
).booleanValue());
872 throw new SocketException("Internal Error: Unexpected type");
878 * @exception IOException If an error occurs
880 public synchronized void close () throws IOException
892 * Converts this <code>Socket</code> to a <code>String</code>.
894 * @return The <code>String</code> representation of this <code>Socket</code>
896 public String
toString ()
898 return("Socket " + impl
);
904 * Sets the <code>SocketImplFactory</code>. This may be done only once per
905 * virtual machine. Subsequent attempts will generate a
906 * <code>SocketException</code>. Note that a <code>SecurityManager</code>
907 * check is made prior to setting the factory. If
908 * insufficient privileges exist to set the factory, then an
909 * <code>IOException</code> will be thrown.
911 * @exception SecurityException If the <code>SecurityManager</code> does
912 * not allow this operation.
913 * @exception SocketException If the SocketImplFactory is already defined
914 * @exception IOException If any other error occurs
916 public static synchronized void setSocketImplFactory (SocketImplFactory fac
)
919 // See if already set
921 throw new SocketException("SocketImplFactory already defined");
924 SecurityManager sm
= System
.getSecurityManager();
926 sm
.checkSetFactory();
929 throw new SocketException("SocketImplFactory cannot be null");
935 * Closes the input side of the socket stream.
937 * @exception IOException If an error occurs.
941 public void shutdownInput() throws IOException
944 impl
.shutdownInput();
946 inputShutdown
= true;
950 * Closes the output side of the socket stream.
952 * @exception IOException If an error occurs.
956 public void shutdownOutput() throws IOException
959 impl
.shutdownOutput();
961 outputShutdown
= true;
965 * Returns the socket channel associated with this socket.
967 * It returns null if no associated socket exists.
971 public SocketChannel
getChannel()
977 * Checks if the SO_REUSEADDR option is enabled
979 * @exception SocketException If an error occurs
983 public boolean getReuseAddress () throws SocketException
985 Object reuseaddr
= impl
.getOption (SocketOptions
.SO_REUSEADDR
);
987 if (!(reuseaddr
instanceof Boolean
))
988 throw new SocketException ("Internal Error");
990 return ((Boolean
) reuseaddr
).booleanValue ();
994 * Enables/Disables the SO_REUSEADDR option
996 * @exception SocketException If an error occurs
1000 public void setReuseAddress (boolean on
) throws SocketException
1002 impl
.setOption (SocketOptions
.SO_REUSEADDR
, new Boolean (on
));
1006 * Returns the current traffic class
1008 * @exception SocketException If an error occurs
1010 * @see Socket#setTrafficClass(int tc)
1014 public int getTrafficClass () throws SocketException
1016 Object obj
= impl
.getOption(SocketOptions
.IP_TOS
);
1018 if (obj
instanceof Integer
)
1019 return ((Integer
) obj
).intValue ();
1021 throw new SocketException ("Unexpected type");
1025 * Sets the traffic class value
1027 * @param tc The traffic class
1029 * @exception SocketException If an error occurs
1030 * @exception IllegalArgumentException If tc value is illegal
1032 * @see Socket#getTrafficClass()
1036 public void setTrafficClass (int tc
) throws SocketException
1038 if (tc
< 0 || tc
> 255)
1039 throw new IllegalArgumentException();
1041 impl
.setOption (SocketOptions
.IP_TOS
, new Integer (tc
));
1045 * Checks if the socket is connected
1049 public boolean isConnected ()
1051 return impl
.getInetAddress () != null;
1055 * Checks if the socket is already bound.
1059 public boolean isBound ()
1061 return getLocalAddress () != null;
1065 * Checks if the socket is closed.
1069 public boolean isClosed ()
1075 * Checks if the socket's input stream is shutdown
1079 public boolean isInputShutdown ()
1081 return inputShutdown
;
1085 * Checks if the socket's output stream is shutdown
1089 public boolean isOutputShutdown ()
1091 return outputShutdown
;