1 /* Socket.java -- Client socket implementation
2 Copyright (C) 1998, 1999, 2000, 2002 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 java
.nio
.channels
.SocketChannel
;
42 import java
.nio
.channels
.IllegalBlockingModeException
;
44 /* Written using on-line Java Platform 1.2 API Specification.
45 * Status: I believe all methods are implemented.
49 * This class models a client site socket. A socket is a TCP/IP endpoint
50 * for network communications conceptually similar to a file handle.
52 * This class does not actually do any work. Instead, it redirects all of
53 * its calls to a socket implementation object which implements the
54 * <code>SocketImpl</code> interface. The implementation class is
55 * instantiated by factory class that implements the
56 * <code>SocketImplFactory interface</code>. A default
57 * factory is provided, however the factory may be set by a call to
58 * the <code>setSocketImplFactory</code> method. Note that this may only be
59 * done once per virtual machine. If a subsequent attempt is made to set the
60 * factory, a <code>SocketException</code> will be thrown.
62 * @author Aaron M. Renn (arenn@urbanophile.com)
63 * @author Per Bothner (bothner@cygnus.com)
71 * This is the user SocketImplFactory for this class. If this variable is
72 * null, a default factory is used.
74 static SocketImplFactory factory
;
79 * The implementation object to which calls are redirected
83 private boolean inputShutdown
;
84 private boolean outputShutdown
;
86 SocketChannel ch
; // this field must have been set if created by SocketChannel
91 * Initializes a new instance of <code>Socket</code> object without
92 * connecting to a remote host. This useful for subclasses of socket that
93 * might want this behavior.
95 * @specnote This constructor is public since JDK 1.4
100 impl
= factory
.createSocketImpl();
102 impl
= new PlainSocketImpl();
104 inputShutdown
= false;
105 outputShutdown
= false;
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. This value can be <code>null</code>, but if it is, all instance
116 * methods in <code>Socket</code> should be overridden because most of them
117 * rely on this value being populated.
119 * @param impl The <code>SocketImpl</code> to use for this
120 * <code>Socket</code>
122 * @exception SocketException If an error occurs
124 protected Socket (SocketImpl impl
) throws SocketException
127 this.inputShutdown
= false;
128 this.outputShutdown
= false;
132 * Initializes a new instance of <code>Socket</code> and connects to the
133 * hostname and port specified as arguments.
135 * @param host The name of the host to connect to
136 * @param port The port number to connect to
138 * @exception UnknownHostException If the hostname cannot be resolved to a
140 * @exception IOException If an error occurs
141 * @exception SecurityException If a security manager exists and its
142 * checkConnect method doesn't allow the operation
144 public Socket (String host
, int port
)
145 throws UnknownHostException
, IOException
147 this(InetAddress
.getByName(host
), port
, null, 0, true);
151 * Initializes a new instance of <code>Socket</code> and connects to the
152 * address and port number specified as arguments.
154 * @param address The address to connect to
155 * @param port The port number to connect to
157 * @exception IOException If an error occurs
158 * @exception SecurityException If a security manager exists and its
159 * checkConnect method doesn't allow the operation
161 public Socket (InetAddress address
, int port
)
164 this(address
, port
, null, 0, true);
168 * Initializes a new instance of <code>Socket</code> that connects to the
169 * named host on the specified port and binds to the specified local address
172 * @param host The name of the remote host to connect to.
173 * @param port The remote port to connect to.
174 * @param loadAddr The local address to bind to.
175 * @param localPort The local port to bind to.
177 * @exception SecurityException If the <code>SecurityManager</code>
178 * exists and does not allow a connection to the specified host/port or
179 * binding to the specified local host/port.
180 * @exception IOException If a connection error occurs.
182 public Socket (String host
, int port
,
183 InetAddress localAddr
, int localPort
) throws IOException
185 this(InetAddress
.getByName(host
), port
, localAddr
, localPort
, true);
189 * Initializes a new instance of <code>Socket</code> and connects to the
190 * address and port number specified as arguments, plus binds to the
191 * specified local address and port.
193 * @param address The remote address to connect to
194 * @param port The remote port to connect to
195 * @param localAddr The local address to connect to
196 * @param localPort The local port to connect to
198 * @exception IOException If an error occurs
199 * @exception SecurityException If a security manager exists and its
200 * checkConnect method doesn't allow the operation
202 public Socket (InetAddress address
, int port
,
203 InetAddress localAddr
, int localPort
) throws IOException
205 this(address
, port
, localAddr
, localPort
, true);
209 * Initializes a new instance of <code>Socket</code> and connects to the
210 * hostname and port specified as arguments. If the stream argument is set
211 * to <code>true</code>, then a stream socket is created. If it is
212 * <code>false</code>, a datagram socket is created.
214 * @param host The name of the host to connect to
215 * @param port The port to connect to
216 * @param stream <code>true</code> for a stream socket, <code>false</code>
217 * for a datagram socket
219 * @exception IOException If an error occurs
220 * @exception SecurityException If a security manager exists and its
221 * checkConnect method doesn't allow the operation
223 * @deprecated Use the <code>DatagramSocket</code> class to create
224 * datagram oriented sockets.
226 public Socket (String host
, int port
, boolean stream
) throws IOException
228 this(InetAddress
.getByName(host
), port
, null, 0, stream
);
232 * Initializes a new instance of <code>Socket</code> and connects to the
233 * address and port number specified as arguments. If the stream param is
234 * <code>true</code>, a stream socket will be created, otherwise a datagram
237 * @param host The address to connect to
238 * @param port The port number to connect to
239 * @param stream <code>true</code> to create a stream socket,
240 * <code>false</code> to create a datagram socket.
242 * @exception IOException If an error occurs
243 * @exception SecurityException If a security manager exists and its
244 * checkConnect method doesn't allow the operation
246 * @deprecated Use the <code>DatagramSocket</code> class to create
247 * datagram oriented sockets.
249 public Socket (InetAddress host
, int port
, boolean stream
) throws IOException
251 this(host
, port
, null, 0, stream
);
255 * This constructor is where the real work takes place. Connect to the
256 * specified address and port. Use default local values if not specified,
257 * otherwise use the local host and port passed in. Create as stream or
258 * datagram based on "stream" argument.
261 * @param raddr The remote address to connect to
262 * @param rport The remote port to connect to
263 * @param laddr The local address to connect to
264 * @param lport The local port to connect to
265 * @param stream true for a stream socket, false for a datagram socket
267 * @exception IOException If an error occurs
268 * @exception SecurityException If a security manager exists and its
269 * checkConnect method doesn't allow the operation
271 private Socket(InetAddress raddr
, int rport
, InetAddress laddr
, int lport
,
272 boolean stream
) throws IOException
275 this.inputShutdown
= false;
276 this.outputShutdown
= false;
279 throw new IOException("Cannot initialize Socket implementation");
281 SecurityManager sm
= System
.getSecurityManager();
283 sm
.checkConnect(raddr
.getHostName(), rport
);
287 // FIXME: JCL p. 1586 says if localPort is unspecified, bind to any port,
288 // i.e. '0' and if localAddr is unspecified, use getLocalAddress() as
289 // that default. JDK 1.2 doc infers not to do a bind.
291 impl
.bind(laddr
, lport
);
294 impl
.connect(raddr
, rport
);
298 * Binds the socket to the givent local address/port
300 * @param bindpoint The address/port to bind to
302 * @exception IOException If an error occurs
303 * @exception SecurityException If a security manager exists and its
304 * checkConnect method doesn't allow the operation
305 * @exception IllegalArgumentException If the address type is not supported
309 public void bind (SocketAddress bindpoint
) throws IOException
311 if ( !(bindpoint
instanceof InetSocketAddress
))
312 throw new IllegalArgumentException ();
314 InetSocketAddress tmp
= (InetSocketAddress
) bindpoint
;
315 impl
.bind (tmp
.getAddress(), tmp
.getPort());
319 * Connects the socket with a remote address.
321 * @param endpoint The address to connect to
323 * @exception IOException If an error occurs
324 * @exception IllegalArgumentException If the addess type is not supported
325 * @exception IllegalBlockingModeException If this socket has an associated
326 * channel, and the channel is in non-blocking mode
330 public void connect (SocketAddress endpoint
)
333 if (! (endpoint
instanceof InetSocketAddress
))
334 throw new IllegalArgumentException ("Address type not supported");
336 if (ch
!= null && !ch
.isBlocking ())
337 throw new IllegalBlockingModeException ();
339 impl
.connect (endpoint
, 0);
343 * Connects the socket with a remote address. A timeout of zero is
344 * interpreted as an infinite timeout. The connection will then block
345 * until established or an error occurs.
347 * @param endpoint The address to connect to
349 * @exception IOException If an error occurs
350 * @exception IllegalArgumentException If the address type is not supported
351 * @exception IllegalBlockingModeException If this socket has an associated
352 * channel, and the channel is in non-blocking mode
353 * @exception SocketTimeoutException If the timeout is reached
357 public void connect (SocketAddress endpoint
, int timeout
)
360 if (! (endpoint
instanceof InetSocketAddress
))
361 throw new IllegalArgumentException ("Address type not supported");
363 if (ch
!= null && !ch
.isBlocking ())
364 throw new IllegalBlockingModeException ();
366 impl
.connect (endpoint
, timeout
);
370 * Returns the address of the remote end of the socket. If this socket
371 * is not connected, then <code>null</code> is returned.
373 * @return The remote address this socket is connected to
375 public InetAddress
getInetAddress ()
378 return impl
.getInetAddress();
384 * Returns the local address to which this socket is bound. If this socket
385 * is not connected, then <code>null</code> is returned.
387 * @return The local address
389 public InetAddress
getLocalAddress ()
394 InetAddress addr
= null;
397 addr
= (InetAddress
)impl
.getOption(SocketOptions
.SO_BINDADDR
);
399 catch(SocketException e
)
401 // (hopefully) shouldn't happen
402 // throw new java.lang.InternalError
403 // ("Error in PlainSocketImpl.getOption");
407 // FIXME: According to libgcj, checkConnect() is supposed to be called
408 // before performing this operation. Problems: 1) We don't have the
409 // addr until after we do it, so we do a post check. 2). The docs I
410 // see don't require this in the Socket case, only DatagramSocket, but
411 // we'll assume they mean both.
412 SecurityManager sm
= System
.getSecurityManager();
414 sm
.checkConnect(addr
.getHostName(), getLocalPort());
420 * Returns the port number of the remote end of the socket connection. If
421 * this socket is not connected, then -1 is returned.
423 * @return The remote port this socket is connected to
425 public int getPort ()
428 return impl
.getPort();
434 * Returns the local port number to which this socket is bound. If this
435 * socket is not connected, then -1 is returned.
437 * @return The local port
439 public int getLocalPort ()
442 return impl
.getLocalPort();
448 * If the socket is already bound this returns the local SocketAddress,
453 public SocketAddress
getLocalSocketAddress()
455 InetAddress addr
= getLocalAddress ();
460 return new InetSocketAddress (addr
, impl
.getLocalPort());
464 * If the socket is already connected this returns the remote SocketAddress,
469 public SocketAddress
getRemoteSocketAddress()
474 return new InetSocketAddress (impl
.getInetAddress (), impl
.getPort ());
478 * Returns an InputStream for reading from this socket.
480 * @return The InputStream object
482 * @exception IOException If an error occurs or Socket is not connected
484 public InputStream
getInputStream () throws IOException
487 return(impl
.getInputStream());
489 throw new IOException("Not connected");
493 * Returns an OutputStream for writing to this socket.
495 * @return The OutputStream object
497 * @exception IOException If an error occurs or Socket is not connected
499 public OutputStream
getOutputStream () throws IOException
502 return impl
.getOutputStream();
504 throw new IOException("Not connected");
508 * Sets the TCP_NODELAY option on the socket.
510 * @param on true to enable, false to disable
512 * @exception SocketException If an error occurs or Socket is not connected
514 public void setTcpNoDelay (boolean on
) throws SocketException
517 throw new SocketException("Not connected");
519 impl
.setOption(SocketOptions
.TCP_NODELAY
, new Boolean(on
));
523 * Tests whether or not the TCP_NODELAY option is set on the socket.
524 * Returns true if enabled, false if disabled. When on it disables the
525 * Nagle algorithm which means that packets are always send immediatly and
526 * never merged together to reduce network trafic.
528 * @return Whether or not TCP_NODELAY is set
530 * @exception SocketException If an error occurs or Socket not connected
532 public boolean getTcpNoDelay() throws SocketException
535 throw new SocketException("Not connected");
537 Object on
= impl
.getOption(SocketOptions
.TCP_NODELAY
);
539 if (on
instanceof Boolean
)
540 return(((Boolean
)on
).booleanValue());
542 throw new SocketException("Internal Error");
546 * Sets the value of the SO_LINGER option on the socket. If the
547 * SO_LINGER option is set on a socket and there is still data waiting to
548 * be sent when the socket is closed, then the close operation will block
549 * until either that data is delivered or until the timeout period
550 * expires. The linger interval is specified in hundreths of a second
551 * (platform specific?)
553 * @param on true to enable SO_LINGER, false to disable
554 * @param linger The SO_LINGER timeout in hundreths of a second or -1 if
557 * @exception SocketException If an error occurs or Socket not connected
558 * @exception IllegalArgumentException If linger is negative
560 public void setSoLinger(boolean on
, int linger
) throws SocketException
563 throw new SocketException("No socket created");
568 throw new IllegalArgumentException("SO_LINGER must be >= 0");
573 impl
.setOption(SocketOptions
.SO_LINGER
, new Integer(linger
));
577 impl
.setOption(SocketOptions
.SO_LINGER
, new Boolean(false));
582 * Returns the value of the SO_LINGER option on the socket. If the
583 * SO_LINGER option is set on a socket and there is still data waiting to
584 * be sent when the socket is closed, then the close operation will block
585 * until either that data is delivered or until the timeout period
586 * expires. This method either returns the timeouts (in hundredths of
587 * of a second (platform specific?)) if SO_LINGER is set, or -1 if
588 * SO_LINGER is not set.
590 * @return The SO_LINGER timeout in hundreths of a second or -1
591 * if SO_LINGER not set
593 * @exception SocketException If an error occurs or Socket is not connected
595 public int getSoLinger() throws SocketException
598 throw new SocketException("Not connected");
600 Object linger
= impl
.getOption(SocketOptions
.SO_LINGER
);
601 if (linger
instanceof Integer
)
602 return(((Integer
)linger
).intValue());
608 * Sends urgent data through the socket
610 * @param data The data to send.
611 * Only the lowest eight bits of data are sent
613 * @exception IOException If an error occurs
617 public void sendUrgentData (int data
) throws IOException
619 impl
.sendUrgentData (data
);
623 * Enables/disables the SO_OOBINLINE option
625 * @param on True if SO_OOBLINE should be enabled
627 * @exception SocketException If an error occurs
631 public void setOOBInline (boolean on
) throws SocketException
634 throw new SocketException("Not connected");
636 impl
.setOption(SocketOptions
.SO_OOBINLINE
, new Boolean(on
));
640 * Returns the current setting of the SO_OOBINLINE option for this socket
642 * @exception SocketException If an error occurs
646 public boolean getOOBInline () throws SocketException
649 throw new SocketException("Not connected");
651 Object buf
= impl
.getOption(SocketOptions
.SO_OOBINLINE
);
653 if (buf
instanceof Boolean
)
654 return(((Boolean
)buf
).booleanValue());
656 throw new SocketException("Internal Error: Unexpected type");
660 * Sets the value of the SO_TIMEOUT option on the socket. If this value
661 * is set, and an read/write is performed that does not complete within
662 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
663 * would be sent in Unix if no data had been read). A value of 0 for
664 * this option implies that there is no timeout (ie, operations will
665 * block forever). On systems that have separate read and write timeout
666 * values, this method returns the read timeout. This
667 * value is in thousandths of a second (****????*****)
669 * @param timeout The length of the timeout in thousandth's of a second or
672 * @exception SocketException If an error occurs or Socket not connected
674 public synchronized void setSoTimeout (int timeout
) throws SocketException
677 throw new SocketException("Not connected");
680 throw new IllegalArgumentException("SO_TIMEOUT value must be >= 0");
682 impl
.setOption(SocketOptions
.SO_TIMEOUT
, new Integer(timeout
));
686 * Returns the value of the SO_TIMEOUT option on the socket. If this value
687 * is set, and an read/write is performed that does not complete within
688 * the timeout period, a short count is returned (or an EWOULDBLOCK signal
689 * would be sent in Unix if no data had been read). A value of 0 for
690 * this option implies that there is no timeout (ie, operations will
691 * block forever). On systems that have separate read and write timeout
692 * values, this method returns the read timeout. This
693 * value is in thousandths of a second (implementation specific?).
695 * @return The length of the timeout in thousandth's of a second or 0
698 * @exception SocketException If an error occurs or Socket not connected
700 public synchronized int getSoTimeout () throws SocketException
703 throw new SocketException("Not connected");
705 Object timeout
= impl
.getOption(SocketOptions
.SO_TIMEOUT
);
706 if (timeout
instanceof Integer
)
707 return(((Integer
)timeout
).intValue());
713 * This method sets the value for the system level socket option
714 * SO_SNDBUF to the specified value. Note that valid values for this
715 * option are specific to a given operating system.
717 * @param size The new send buffer size.
719 * @exception SocketException If an error occurs or Socket not connected
720 * @exception IllegalArgumentException If size is 0 or negative
724 public void setSendBufferSize (int size
) throws SocketException
727 throw new SocketException("Not connected");
730 throw new IllegalArgumentException("SO_SNDBUF value must be > 0");
732 impl
.setOption(SocketOptions
.SO_SNDBUF
, new Integer(size
));
736 * This method returns the value of the system level socket option
737 * SO_SNDBUF, which is used by the operating system to tune buffer
738 * sizes for data transfers.
740 * @return The send buffer size.
742 * @exception SocketException If an error occurs or socket not connected
746 public int getSendBufferSize () throws SocketException
749 throw new SocketException("Not connected");
751 Object buf
= impl
.getOption(SocketOptions
.SO_SNDBUF
);
753 if (buf
instanceof Integer
)
754 return(((Integer
)buf
).intValue());
756 throw new SocketException("Internal Error: Unexpected type");
760 * This method sets the value for the system level socket option
761 * SO_RCVBUF to the specified value. Note that valid values for this
762 * option are specific to a given operating system.
764 * @param size The new receive buffer size.
766 * @exception SocketException If an error occurs or Socket is not connected
767 * @exception IllegalArgumentException If size is 0 or negative
771 public void setReceiveBufferSize (int size
) throws SocketException
774 throw new SocketException("Not connected");
777 throw new IllegalArgumentException("SO_RCVBUF value must be > 0");
779 impl
.setOption(SocketOptions
.SO_RCVBUF
, new Integer(size
));
783 * This method returns the value of the system level socket option
784 * SO_RCVBUF, which is used by the operating system to tune buffer
785 * sizes for data transfers.
787 * @return The receive buffer size.
789 * @exception SocketException If an error occurs or Socket is not connected
793 public int getReceiveBufferSize () throws SocketException
796 throw new SocketException("Not connected");
798 Object buf
= impl
.getOption(SocketOptions
.SO_RCVBUF
);
800 if (buf
instanceof Integer
)
801 return(((Integer
)buf
).intValue());
803 throw new SocketException("Internal Error: Unexpected type");
807 * This method sets the value for the socket level socket option
810 * @param on True if SO_KEEPALIVE should be enabled
812 * @exception SocketException If an error occurs or Socket is not connected
816 public void setKeepAlive (boolean on
) throws SocketException
819 throw new SocketException("Not connected");
821 impl
.setOption(SocketOptions
.SO_KEEPALIVE
, new Boolean(on
));
825 * This method returns the value of the socket level socket option
828 * @return The setting
830 * @exception SocketException If an error occurs or Socket is not connected
834 public boolean getKeepAlive () throws SocketException
837 throw new SocketException("Not connected");
839 Object buf
= impl
.getOption(SocketOptions
.SO_KEEPALIVE
);
841 if (buf
instanceof Boolean
)
842 return(((Boolean
)buf
).booleanValue());
844 throw new SocketException("Internal Error: Unexpected type");
850 * @exception IOException If an error occurs
852 public synchronized void close () throws IOException
859 * Converts this <code>Socket</code> to a <code>String</code>.
861 * @return The <code>String</code> representation of this <code>Socket</code>
863 public String
toString ()
865 return("Socket " + impl
);
871 * Sets the <code>SocketImplFactory</code>. This may be done only once per
872 * virtual machine. Subsequent attempts will generate a
873 * <code>SocketException</code>. Note that a <code>SecurityManager</code>
874 * check is made prior to setting the factory. If
875 * insufficient privileges exist to set the factory, then an
876 * <code>IOException</code> will be thrown.
878 * @exception SecurityException If the <code>SecurityManager</code> does
879 * not allow this operation.
880 * @exception SocketException If the SocketImplFactory is already defined
881 * @exception IOException If any other error occurs
883 public static synchronized void setSocketImplFactory (SocketImplFactory fac
)
886 // See if already set
888 throw new SocketException("SocketImplFactory already defined");
891 SecurityManager sm
= System
.getSecurityManager();
893 sm
.checkSetFactory();
896 throw new SocketException("SocketImplFactory cannot be null");
902 * Closes the input side of the socket stream.
904 * @exception IOException If an error occurs.
906 public void shutdownInput() throws IOException
909 impl
.shutdownInput();
911 inputShutdown
= true;
915 * Closes the output side of the socket stream.
917 * @exception IOException If an error occurs.
919 public void shutdownOutput() throws IOException
922 impl
.shutdownOutput();
924 outputShutdown
= true;
928 * Returns the socket channel associated with this socket.
930 * It returns null if no associated socket exists.
932 public SocketChannel
getChannel()
938 * Checks if the SO_REUSEADDR option is enabled
940 * @exception SocketException If an error occurs
944 public boolean getReuseAddress () throws SocketException
947 throw new SocketException ("Cannot initialize Socket implementation");
949 Object reuseaddr
= impl
.getOption (SocketOptions
.SO_REUSEADDR
);
951 if (!(reuseaddr
instanceof Boolean
))
952 throw new SocketException ("Internal Error");
954 return ((Boolean
) reuseaddr
).booleanValue ();
958 * Enables/Disables the SO_REUSEADDR option
960 * @exception SocketException If an error occurs
964 public void setReuseAddress (boolean on
) throws SocketException
967 throw new SocketException ("Cannot initialize Socket implementation");
969 impl
.setOption (SocketOptions
.SO_REUSEADDR
, new Boolean (on
));
973 * Returns the current traffic class
975 * @exception SocketException If an error occurs
977 * @see Socket:setTrafficClass
981 public int getTrafficClass () throws SocketException
984 throw new SocketException ("Cannot initialize Socket implementation");
986 Object obj
= impl
.getOption(SocketOptions
.IP_TOS
);
988 if (obj
instanceof Integer
)
989 return ((Integer
) obj
).intValue ();
991 throw new SocketException ("Unexpected type");
995 * Sets the traffic class value
997 * @param tc The traffic class
999 * @exception SocketException If an error occurs
1000 * @exception IllegalArgumentException If tc value is illegal
1002 * @see Socket:getTrafficClass
1006 public void setTrafficClass (int tc
) throws SocketException
1009 throw new SocketException ("Cannot initialize Socket implementation");
1011 if (tc
< 0 || tc
> 255)
1012 throw new IllegalArgumentException();
1014 impl
.setOption (SocketOptions
.IP_TOS
, new Integer (tc
));
1018 * Checks if the socket is connected
1020 public boolean isConnected ()
1022 return impl
.getInetAddress () != null;
1026 * Checks if the socket is already bound.
1028 public boolean isBound ()
1030 return getLocalAddress () != null;
1034 * Checks if the socket is closed.
1036 public boolean isClosed ()
1038 // FIXME: implement this.
1043 * Checks if the socket's input stream is shutdown
1045 public boolean isInputShutdown ()
1047 return inputShutdown
;
1051 * Checks if the socket's output stream is shutdown
1053 public boolean isOutputShutdown ()
1055 return outputShutdown
;