|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.net.Socket
org.p2psockets.P2PSocket
This class implements client sockets (also called just "sockets"). A socket is an endpoint for communication between two machines. Threading: this class is not threadsafe and should only be used from one thread. It is unclear if using the socket's input stream in one thread and the output stream in another thread will be threadsafe; it is also unclear if the original java.net.Sockets supports this.
Field Summary | |
protected net.jxta.socket.JxtaSocket |
jxtaSocket
The JXTA socket that actually does all the hard work. |
protected P2PSocketAddress |
localSocketAddress
The local end of the socket connection. |
protected P2PSocketAddress |
remoteSocketAddress
The remote end of the socket connection. |
protected static int |
SEND_BUFFER_SIZE
This is a random number that has no real meaning; we need is for getSoSendBufferSize(), which has no corresponding JXTA value. |
protected java.io.InputStream |
socketIn
|
protected java.io.OutputStream |
socketOut
|
Constructor Summary | |
|
P2PSocket()
Creates an unconnected socket. |
|
P2PSocket(java.net.InetAddress address,
int port)
Creates a stream socket and connects it to the specified port number at the specified IP address. |
|
P2PSocket(java.net.InetAddress address,
int port,
boolean stream)
Creates a socket and connects it to the specified port number at the specified IP address. |
|
P2PSocket(java.net.InetAddress address,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote address on the specified remote port. |
protected |
P2PSocket(net.jxta.socket.JxtaSocket clientJxtaSocket,
java.lang.String remoteHost,
int remotePort,
java.net.InetAddress localAddress,
int localPort)
Used by P2PServerSocket to create the socket returned by the accept() method. |
|
P2PSocket(java.lang.String host,
int port)
Creates a stream socket and connects it to the specified port number on the named host. |
|
P2PSocket(java.lang.String host,
int port,
boolean stream)
Creates a stream socket and connects it to the specified port number on the named host. |
|
P2PSocket(java.lang.String host,
int port,
java.net.InetAddress localAddr,
int localPort)
Creates a socket and connects it to the specified remote host on the specified remote port. |
Method Summary | |
void |
bind(java.net.SocketAddress bindpoint)
Binds the socket to a local address. |
void |
close()
Closes this socket. |
void |
connect(java.net.SocketAddress endpoint)
Connects this socket to the server. |
void |
connect(java.net.SocketAddress endpoint,
int timeout)
Connects this socket to the server with a specified timeout value. |
java.net.InetAddress |
getInetAddress()
Returns the address to which the socket is connected. |
java.io.InputStream |
getInputStream()
Returns an input stream for this socket. |
boolean |
getKeepAlive()
|
java.net.InetAddress |
getLocalAddress()
Gets the local address to which the socket is bound. |
int |
getLocalPort()
Returns the local port to which this socket is bound. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet. |
boolean |
getOOBInline()
|
java.io.OutputStream |
getOutputStream()
Returns an output stream for this socket. |
int |
getPort()
Returns the remote port to which this socket is connected. |
int |
getReceiveBufferSize()
|
java.net.SocketAddress |
getRemoteSocketAddress()
Returns the address of the endpoint this socket is connected to, or null if it is unconnected. |
boolean |
getReuseAddress()
|
int |
getSendBufferSize()
|
int |
getSoLinger()
|
int |
getSoTimeout()
|
boolean |
getTcpNoDelay()
|
int |
getTrafficClass()
|
boolean |
isBound()
|
boolean |
isClosed()
|
boolean |
isConnected()
|
boolean |
isInputShutdown()
|
boolean |
isOutputShutdown()
|
void |
sendUrgentData(int data)
|
void |
setKeepAlive(boolean on)
|
void |
setOOBInline(boolean on)
|
void |
setReceiveBufferSize(int size)
|
void |
setReuseAddress(boolean on)
|
void |
setSendBufferSize(int size)
|
static void |
setSocketImplFactory(java.net.SocketImplFactory fac)
|
void |
setSoLinger(boolean on,
int linger)
|
void |
setSoTimeout(int timeout)
|
void |
setTcpNoDelay(boolean on)
|
void |
setTrafficClass(int tc)
|
void |
shutdownInput()
Places the input stream for this socket at "end of stream". |
void |
shutdownOutput()
Disables the output stream for this socket. |
java.lang.String |
toString()
Converts this socket to a String . |
Methods inherited from class java.net.Socket |
getChannel |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
protected P2PSocketAddress remoteSocketAddress
protected P2PSocketAddress localSocketAddress
protected net.jxta.socket.JxtaSocket jxtaSocket
protected java.io.InputStream socketIn
protected java.io.OutputStream socketOut
protected static final int SEND_BUFFER_SIZE
Constructor Detail |
public P2PSocket()
public P2PSocket(java.lang.String host, int port) throws java.net.UnknownHostException, java.io.IOException
host
- the host name.port
- the port number.
java.net.UnknownHostException
- if the IP address of
the host could not be determined.
java.io.IOException
- if an I/O error occurs when creating the socket.public P2PSocket(java.net.InetAddress address, int port) throws java.io.IOException
address
- the IP address.port
- the port number.
java.io.IOException
- if an I/O error occurs when creating the socket.public P2PSocket(java.lang.String host, int port, java.net.InetAddress localAddr, int localPort) throws java.io.IOException
host
- the name of the remote hostport
- the remote portlocalAddr
- the local address the socket is socketBound to. This value
is ignored, since JXTA peers are not multihomed.localPort
- the local port the socket is socketBound to
java.io.IOException
- if an I/O error occurs when creating the socket.public P2PSocket(java.net.InetAddress address, int port, java.net.InetAddress localAddr, int localPort) throws java.io.IOException
address
- the remote addressport
- the remote portlocalAddr
- the local address the socket is socketBound to. This value
is ignored, since JXTA peers are not multihomed.localPort
- the local port the socket is socketBound to
java.io.IOException
- if an I/O error occurs when creating the socket.public P2PSocket(java.lang.String host, int port, boolean stream) throws java.io.IOException
host
- the host name.port
- the port number.stream
- a boolean
indicating whether this is
a stream socket or a datagram socket.
java.io.IOException
- if an I/O error occurs when creating the socket.public P2PSocket(java.net.InetAddress address, int port, boolean stream) throws java.io.IOException
port
- the port number.stream
- if true
, create a stream socket;
otherwise, create a datagram socket.
java.io.IOException
- if an I/O error occurs when creating the socket.protected P2PSocket(net.jxta.socket.JxtaSocket clientJxtaSocket, java.lang.String remoteHost, int remotePort, java.net.InetAddress localAddress, int localPort) throws java.io.IOException
Method Detail |
public void connect(java.net.SocketAddress endpoint) throws java.io.IOException
endpoint
- the P2PSocketAddress
java.io.IOException
- if an error occurs during the connection
java.lang.IllegalArgumentException
- if endpoint is null or is a
SocketAddress subclass not supported by this socketpublic void connect(java.net.SocketAddress endpoint, int timeout) throws java.io.IOException
endpoint
- the SocketAddress
timeout
- the timeout value to be used in milliseconds.
Timeout values are not currently supported by P2P Sockets.
java.io.IOException
- if an error occurs during the connection
java.net.SocketTimeoutException
- if timeout expires before connecting
java.lang.IllegalArgumentException
- if endpoint is null or is a
SocketAddress subclass not supported by this socketpublic void bind(java.net.SocketAddress bindpoint) throws java.io.IOException
If the address is null
, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
bindpoint
- the SocketAddress
to bind to
java.io.IOException
- if the bind operation fails, or if the socket
is already bound.
java.lang.IllegalArgumentException
- if bindpoint is a
SocketAddress subclass not supported by this socketpublic java.net.InetAddress getInetAddress()
null
if the socket is not connected.public java.net.InetAddress getLocalAddress()
InetAddress.anyLocalAddress()
if the socket is not bound yet.public int getPort()
public int getLocalPort()
public java.net.SocketAddress getRemoteSocketAddress()
null
if it is unconnected.
SocketAddress
reprensenting the remote endpoint of this
socket, or null
if it is not connected yet.public java.net.SocketAddress getLocalSocketAddress()
null
if it is not bound yet.
SocketAddress
representing the local endpoint of this
socket, or null
if it is not bound yet.public java.io.InputStream getInputStream() throws java.io.IOException
java.io.IOException
- if an I/O error occurs when creating the
input stream, the socket is closed, the socket is
not socketConnected, or the socket input has been shutdown
using shutdownInput()
public java.io.OutputStream getOutputStream() throws java.io.IOException
java.io.IOException
- if an I/O error occurs when creating the
output stream or if the socket is not connected.public void setTcpNoDelay(boolean on) throws java.net.SocketException
java.net.SocketException
public boolean getTcpNoDelay() throws java.net.SocketException
java.net.SocketException
public void setSoLinger(boolean on, int linger) throws java.net.SocketException
java.net.SocketException
public int getSoLinger() throws java.net.SocketException
java.net.SocketException
public void sendUrgentData(int data) throws java.io.IOException
java.io.IOException
public void setOOBInline(boolean on) throws java.net.SocketException
java.net.SocketException
public boolean getOOBInline() throws java.net.SocketException
java.net.SocketException
public void setSoTimeout(int timeout) throws java.net.SocketException
java.net.SocketException
public int getSoTimeout() throws java.net.SocketException
java.net.SocketException
public void setSendBufferSize(int size) throws java.net.SocketException
java.net.SocketException
public int getSendBufferSize() throws java.net.SocketException
java.net.SocketException
public void setReceiveBufferSize(int size) throws java.net.SocketException
java.net.SocketException
public int getReceiveBufferSize() throws java.net.SocketException
java.net.SocketException
public void setKeepAlive(boolean on) throws java.net.SocketException
java.net.SocketException
public boolean getKeepAlive() throws java.net.SocketException
java.net.SocketException
public void setTrafficClass(int tc) throws java.net.SocketException
java.net.SocketException
public int getTrafficClass() throws java.net.SocketException
java.net.SocketException
public void setReuseAddress(boolean on) throws java.net.SocketException
java.net.SocketException
public boolean getReuseAddress() throws java.net.SocketException
java.net.SocketException
public void close() throws java.io.IOException
Any thread currently blocked in an I/O operation upon this socket
will throw a SocketException
.
Once a socket has been closed, it is not available for further networking use (i.e. can't be reconnected or rebound). A new socket needs to be created.
java.io.IOException
- if an I/O error occurs when closing this socket.public void shutdownInput() throws java.io.IOException
If you read from a socket input stream after invoking shutdownInput() on the socket, the stream will return EOF.
java.io.IOException
- if an I/O error occurs when shutting down this
socket.public void shutdownOutput() throws java.io.IOException
java.io.IOException
- if an I/O error occurs when shutting down this
socket.public boolean isConnected()
public boolean isBound()
public boolean isClosed()
public boolean isInputShutdown()
public boolean isOutputShutdown()
public java.lang.String toString()
String
.
public static void setSocketImplFactory(java.net.SocketImplFactory fac) throws java.io.IOException
java.io.IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |