38 |
package java.net; |
package java.net; |
39 |
|
|
40 |
import java.io.*; |
import java.io.*; |
41 |
import java.nio.channels.*; |
import java.nio.channels.SocketChannel; |
42 |
|
import java.nio.channels.IllegalBlockingModeException; |
43 |
|
|
44 |
/* Written using on-line Java Platform 1.2 API Specification. |
/* Written using on-line Java Platform 1.2 API Specification. |
45 |
* Status: I believe all methods are implemented. |
* Status: I believe all methods are implemented. |
80 |
*/ |
*/ |
81 |
SocketImpl impl; |
SocketImpl impl; |
82 |
|
|
83 |
|
SocketChannel ch; // this field must have been set if created by SocketChannel |
84 |
|
|
85 |
// Constructors |
// Constructors |
86 |
|
|
87 |
/** |
/** |
88 |
* Initializes a new instance of <code>Socket</code> object without |
* Initializes a new instance of <code>Socket</code> object without |
89 |
* connecting to a remote host. This useful for subclasses of socket that |
* connecting to a remote host. This useful for subclasses of socket that |
90 |
* might want this behavior. |
* might want this behavior. |
91 |
|
* |
92 |
|
* @specnote This constructor is public since JDK 1.4 |
93 |
*/ |
*/ |
94 |
protected Socket () |
public Socket () |
95 |
{ |
{ |
96 |
if (factory != null) |
if (factory != null) |
97 |
impl = factory.createSocketImpl(); |
impl = factory.createSocketImpl(); |
130 |
* @exception UnknownHostException If the hostname cannot be resolved to a |
* @exception UnknownHostException If the hostname cannot be resolved to a |
131 |
* network address. |
* network address. |
132 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
133 |
|
* @exception SecurityException If a security manager exists and its |
134 |
|
* checkConnect method doesn't allow the operation |
135 |
*/ |
*/ |
136 |
public Socket (String host, int port) |
public Socket (String host, int port) |
137 |
throws UnknownHostException, IOException |
throws UnknownHostException, IOException |
147 |
* @param port The port number to connect to |
* @param port The port number to connect to |
148 |
* |
* |
149 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
150 |
|
* @exception SecurityException If a security manager exists and its |
151 |
|
* checkConnect method doesn't allow the operation |
152 |
*/ |
*/ |
153 |
public Socket (InetAddress address, int port) |
public Socket (InetAddress address, int port) |
154 |
throws IOException |
throws IOException |
188 |
* @param localPort The local port to connect to |
* @param localPort The local port to connect to |
189 |
* |
* |
190 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
191 |
|
* @exception SecurityException If a security manager exists and its |
192 |
|
* checkConnect method doesn't allow the operation |
193 |
*/ |
*/ |
194 |
public Socket (InetAddress address, int port, |
public Socket (InetAddress address, int port, |
195 |
InetAddress localAddr, int localPort) throws IOException |
InetAddress localAddr, int localPort) throws IOException |
209 |
* for a datagram socket |
* for a datagram socket |
210 |
* |
* |
211 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
212 |
|
* @exception SecurityException If a security manager exists and its |
213 |
|
* checkConnect method doesn't allow the operation |
214 |
* |
* |
215 |
* @deprecated Use the <code>DatagramSocket</code> class to create |
* @deprecated Use the <code>DatagramSocket</code> class to create |
216 |
* datagram oriented sockets. |
* datagram oriented sockets. |
232 |
* <code>false</code> to create a datagram socket. |
* <code>false</code> to create a datagram socket. |
233 |
* |
* |
234 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
235 |
|
* @exception SecurityException If a security manager exists and its |
236 |
|
* checkConnect method doesn't allow the operation |
237 |
* |
* |
238 |
* @deprecated Use the <code>DatagramSocket</code> class to create |
* @deprecated Use the <code>DatagramSocket</code> class to create |
239 |
* datagram oriented sockets. |
* datagram oriented sockets. |
257 |
* @param stream true for a stream socket, false for a datagram socket |
* @param stream true for a stream socket, false for a datagram socket |
258 |
* |
* |
259 |
* @exception IOException If an error occurs |
* @exception IOException If an error occurs |
260 |
|
* @exception SecurityException If a security manager exists and its |
261 |
|
* checkConnect method doesn't allow the operation |
262 |
*/ |
*/ |
263 |
private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport, |
private Socket(InetAddress raddr, int rport, InetAddress laddr, int lport, |
264 |
boolean stream) throws IOException |
boolean stream) throws IOException |
442 |
* SO_LINGER not set. |
* SO_LINGER not set. |
443 |
* |
* |
444 |
* @exception SocketException If an error occurs or Socket not connected |
* @exception SocketException If an error occurs or Socket not connected |
445 |
|
* @exception IllegalArgumentException If linger is negative |
446 |
*/ |
*/ |
447 |
public void setSoLinger(boolean on, int linger) throws SocketException |
public void setSoLinger(boolean on, int linger) throws SocketException |
448 |
{ |
{ |
552 |
* @param size The new send buffer size. |
* @param size The new send buffer size. |
553 |
* |
* |
554 |
* @exception SocketException If an error occurs or Socket not connected |
* @exception SocketException If an error occurs or Socket not connected |
555 |
|
* @exception IllegalArgumentException If size is 0 or negative |
556 |
* |
* |
557 |
* @since 1.2 |
* @since 1.2 |
558 |
*/ |
*/ |
599 |
* @param size The new receive buffer size. |
* @param size The new receive buffer size. |
600 |
* |
* |
601 |
* @exception SocketException If an error occurs or Socket is not connected |
* @exception SocketException If an error occurs or Socket is not connected |
602 |
|
* @exception IllegalArgumentException If size is 0 or negative |
603 |
* |
* |
604 |
* @since 1.2 |
* @since 1.2 |
605 |
*/ |
*/ |
689 |
factory = fac; |
factory = fac; |
690 |
} |
} |
691 |
|
|
692 |
|
/** |
693 |
|
* Closes the input side of the socket stream. |
694 |
|
* |
695 |
|
* @exception IOException If an error occurs. |
696 |
|
*/ |
697 |
public void shutdownInput() throws IOException |
public void shutdownInput() throws IOException |
698 |
{ |
{ |
699 |
// impl.shutdownInput(); |
// impl.shutdownInput(); |
700 |
} |
} |
701 |
|
|
702 |
|
/** |
703 |
|
* Closes the output side of the socket stream. |
704 |
|
* |
705 |
|
* @exception IOException If an error occurs. |
706 |
|
*/ |
707 |
public void shutdownOutput() throws IOException |
public void shutdownOutput() throws IOException |
708 |
{ |
{ |
709 |
// impl.shutdownOutput(); |
// impl.shutdownOutput(); |
710 |
} |
} |
711 |
|
|
|
SocketChannel ch; // this field must have been set if created by SocketChannel |
|
|
|
|
712 |
/** |
/** |
713 |
* Returns the socket channel associated with |
* Returns the socket channel associated with this socket. |
714 |
* this socket. |
* |
|
* |
|
715 |
* It returns null if no associated socket exists. |
* It returns null if no associated socket exists. |
716 |
*/ |
*/ |
717 |
public SocketChannel getChannel() |
public SocketChannel getChannel() |
718 |
{ |
{ |
719 |
return ch; |
return ch; |
720 |
} |
} |