Java Doc for Socket.java in  » Apache-Harmony-Java-SE » java-package » java » net » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Apache Harmony Java SE » java package » java.net 
Source Cross Reference  Class Diagram Java Document (Java Doc) 


java.lang.Object
   java.net.Socket

Socket
public class Socket (Code)
This class represents sockets to be used in connection-oriented (streaming) protocols.


Field Summary
final static  intFLAG_SHUTDOWN
    
final static  intMULTICAST_IF
    
final static  intMULTICAST_TTL
    
final static  intTCP_NODELAY
    
static  SocketImplFactoryfactory
    
 SocketImplimpl
    

Constructor Summary
public  Socket()
     Construct a connection-oriented Socket.
public  Socket(Proxy proxy)
     Constructs a connection-oriented Socket with specified proxy.
public  Socket(String dstName, int dstPort)
     Construct a stream socket connected to the nominated destination host/port.
public  Socket(String dstName, int dstPort, InetAddress localAddress, int localPort)
     Construct a stream socket connected to the nominated destination host/port.
public  Socket(String hostName, int port, boolean streaming)
     Answer a new socket.
public  Socket(InetAddress dstAddress, int dstPort)
     Construct a stream socket connected to the nominated destination host address/port.
public  Socket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort)
     Construct a stream socket connected to the nominated destination host address/port.
public  Socket(InetAddress addr, int port, boolean streaming)
     Answer a new socket.
protected  Socket(SocketImpl anImpl)
     Creates an unconnected socket, wrapping the socketImpl argument.

Method Summary
 voidaccepted()
     Set the appropriate flags for a Socket created by ServerSocket.accept().
public  voidbind(SocketAddress localAddr)
     Bind the Socket to the nominated local host/port.
 voidcheckDestination(InetAddress destAddr, int dstPort)
     Check the connection destination satisfies the security policy and is in the valid port range.
public synchronized  voidclose()
     Close the socket.
public  voidconnect(SocketAddress remoteAddr)
     Connect the Socket to the host/port specified by the SocketAddress.
public  voidconnect(SocketAddress remoteAddr, int timeout)
     Connect the Socket to the host/port specified by the SocketAddress with a specified timeout.
public  SocketChannelgetChannel()
    
public  InetAddressgetInetAddress()
     Returns an InetAddress instance representing the address this socket has connected to. if this socket is connected, the address it is connected to.
public  InputStreamgetInputStream()
     Answer the socket input stream, to read byte data off the socket.
public  booleangetKeepAlive()
     Answer the SO_KEEPALIVE option for this socket.
public  InetAddressgetLocalAddress()
     Returns an InetAddress instance representing the local address this socket is bound to.
public  intgetLocalPort()
     Answer the local port to which the socket is bound.
public  SocketAddressgetLocalSocketAddress()
     Answer the local SocketAddress for this socket, or null if the socket is not bound.
public  booleangetOOBInline()
     Get the state of the SO_OOBINLINE socket option.
public  OutputStreamgetOutputStream()
     Answer the socket output stream, for writing byte data on the socket.
public  intgetPort()
     Returns the number of the remote port this socket is connected to. int the remote port number that this socket has connected to.
public synchronized  intgetReceiveBufferSize()
     Answer the socket receive buffer size (SO_RCVBUF).
public  SocketAddressgetRemoteSocketAddress()
     Answer the remote SocketAddress for this socket, or null if the socket is not connected.
public  booleangetReuseAddress()
     Get the state of the SO_REUSEADDR socket option.
public synchronized  intgetSendBufferSize()
     Answer the socket send buffer size (SO_SNDBUF).
public  intgetSoLinger()
     Answer the linger-on-close timeout for this socket (the SO_LINGER value). this socket's SO_LINGER value.
public synchronized  intgetSoTimeout()
     Answer the socket read timeout.
public  booleangetTcpNoDelay()
     Answer true if the socket is using Nagle's algorithm.
public  intgetTrafficClass()
     Get the IP_TOS socket option.
public  booleanisBound()
     Return if the socket is bound to a local address and port.
public  booleanisClosed()
     Return if the socket is closed.
public  booleanisConnected()
     Return if the socket is connected.
public  booleanisInputShutdown()
     Return if Socket.shutdownInput has been called.
public  booleanisOutputShutdown()
     Return if Socket.shutdownOutput has been called.
static  booleanpreferIPv4Stack()
    
public  voidsendUrgentData(int value)
     Send the single byte of urgent data on the socket.
public  voidsetKeepAlive(boolean value)
     Set the SO_KEEPALIVE option for this socket.
public  voidsetOOBInline(boolean oobinline)
     Set the SO_OOBINLINE socket option.
public  voidsetPerformancePreferences(int connectionTime, int latency, int bandwidth)
    
public synchronized  voidsetReceiveBufferSize(int size)
     Set the socket receive buffer size.
public  voidsetReuseAddress(boolean reuse)
     Set the SO_REUSEADDR socket option.
public synchronized  voidsetSendBufferSize(int size)
     Set the socket send buffer size.
public  voidsetSoLinger(boolean on, int timeout)
     Set the SO_LINGER option, with the specified time, in seconds.
public synchronized  voidsetSoTimeout(int timeout)
     Set the read timeout on this socket.
public static synchronized  voidsetSocketImplFactory(SocketImplFactory fac)
     Specifies the application's socket implementation factory.
public  voidsetTcpNoDelay(boolean on)
     Set whether the socket is to use Nagle's algorithm.
public  voidsetTrafficClass(int value)
     Set the IP_TOS socket option.
public  voidshutdownInput()
     Shutdown the input portion of the socket.
public  voidshutdownOutput()
     Shutdown the output portion of the socket.
 voidstartupSocket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort, boolean streaming)
     Creates a stream socket, binds it to the nominated local address/port, then connects it to the nominated destination address/port.
public  StringtoString()
     Answers a string containing a concise, human-readable description of the socket.

Field Detail
FLAG_SHUTDOWN
final static int FLAG_SHUTDOWN(Code)



MULTICAST_IF
final static int MULTICAST_IF(Code)



MULTICAST_TTL
final static int MULTICAST_TTL(Code)



TCP_NODELAY
final static int TCP_NODELAY(Code)



factory
static SocketImplFactory factory(Code)



impl
SocketImpl impl(Code)




Constructor Detail
Socket
public Socket()(Code)
Construct a connection-oriented Socket. The Socket is created in the factory if declared, or otherwise of the default type.
See Also:   SocketImplFactory



Socket
public Socket(Proxy proxy)(Code)
Constructs a connection-oriented Socket with specified proxy. Method checkConnect is called if a security manager exists, and the proxy host address and port number are passed as parameters.
Parameters:
  proxy - the specified proxy for this Socket.
throws:
  IllegalArgumentException - if the proxy is null or of an invalid type.
throws:
  SecurityException - if a security manager exists and it denies the permission toconnect to proxy.



Socket
public Socket(String dstName, int dstPort) throws UnknownHostException, IOException(Code)
Construct a stream socket connected to the nominated destination host/port. By default, the socket binds it to any available port on the default localhost.
Parameters:
  dstName - the destination host to connect to
Parameters:
  dstPort - the port on the destination host to connect to
throws:
  UnknownHostException - if the host cannot be resolved
throws:
  IOException - if an error occurs while instantiating the socket



Socket
public Socket(String dstName, int dstPort, InetAddress localAddress, int localPort) throws IOException(Code)
Construct a stream socket connected to the nominated destination host/port. The socket is bound it to the nominated localAddress/port.
Parameters:
  dstName - the destination host to connect to
Parameters:
  dstPort - the port on the destination host to connect to
Parameters:
  localAddress - the local host address to bind to
Parameters:
  localPort - the local port to bind to
throws:
  UnknownHostException - if the host cannot be resolved
throws:
  IOException - if an error occurs while instantiating the socket



Socket
public Socket(String hostName, int port, boolean streaming) throws IOException(Code)
Answer a new socket. This constructor is deprecated.
Parameters:
  hostName - the host name
Parameters:
  port - the port on the host
Parameters:
  streaming - if true, answer a stream socket, else answer a a datagramsocket.
throws:
  UnknownHostException - if the host cannot be resolved
throws:
  IOException - if an error occurs while instantiating the socket
See Also:   Socket.Socket(String,int)



Socket
public Socket(InetAddress dstAddress, int dstPort) throws IOException(Code)
Construct a stream socket connected to the nominated destination host address/port. By default, the socket binds it to any available port on the default localhost.
Parameters:
  dstAddress - the destination host address to connect to
Parameters:
  dstPort - the port on the destination host to connect to
throws:
  IOException - if an error occurs while instantiating the socket



Socket
public Socket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort) throws IOException(Code)
Construct a stream socket connected to the nominated destination host address/port. The socket is bound it to the nominated localAddress/port.
Parameters:
  dstAddress - the destination host address to connect to
Parameters:
  dstPort - the port on the destination host to connect to
Parameters:
  localAddress - the local host address to bind to
Parameters:
  localPort - the local port to bind to
throws:
  IOException - if an error occurs while instantiating the socket



Socket
public Socket(InetAddress addr, int port, boolean streaming) throws IOException(Code)
Answer a new socket. This constructor is deprecated.
Parameters:
  addr - the internet address
Parameters:
  port - the port on the host
Parameters:
  streaming - if true, answer a stream socket, else answer a datagramsocket.
throws:
  UnknownHostException - if the host cannot be resolved
throws:
  IOException - if an error occurs while instantiating the socket
See Also:   Socket.Socket(InetAddress,int)



Socket
protected Socket(SocketImpl anImpl) throws SocketException(Code)
Creates an unconnected socket, wrapping the socketImpl argument.
Parameters:
  anImpl - the socket to wrap
throws:
  SocketException - if an error occurs assigning the implementation




Method Detail
accepted
void accepted()(Code)
Set the appropriate flags for a Socket created by ServerSocket.accept().
See Also:   ServerSocket.implAccept



bind
public void bind(SocketAddress localAddr) throws IOException(Code)
Bind the Socket to the nominated local host/port.
Parameters:
  localAddr - the local machine address and port to bind on
throws:
  IllegalArgumentException - if the SocketAddress is not supported
throws:
  IOException - if the socket is already bound, or a problem occurs duringthe bind



checkDestination
void checkDestination(InetAddress destAddr, int dstPort)(Code)
Check the connection destination satisfies the security policy and is in the valid port range.
Parameters:
  destAddr - the destination host address
Parameters:
  dstPort - the port on the destination host



close
public synchronized void close() throws IOException(Code)
Close the socket. It is not valid to use the socket thereafter.
throws:
  IOException - if an error occurs during the close



connect
public void connect(SocketAddress remoteAddr) throws IOException(Code)
Connect the Socket to the host/port specified by the SocketAddress.
Parameters:
  remoteAddr - the remote machine address and port to connect to
throws:
  IllegalArgumentException - if the SocketAddress is not supported
throws:
  IOException - if the socket is already connected, or a problem occursduring the connect



connect
public void connect(SocketAddress remoteAddr, int timeout) throws IOException(Code)
Connect the Socket to the host/port specified by the SocketAddress with a specified timeout.
Parameters:
  remoteAddr - the remote machine address and port to connect to
Parameters:
  timeout - the millisecond timeout value, the connect will blockindefinitely for a zero value.
throws:
  IllegalArgumentException - if the timeout is negative, or the SocketAddress is notsupported
throws:
  IOException - if the socket is already connected, or a problem occursduring the connect



getChannel
public SocketChannel getChannel()(Code)
if Socket is created by a SocketChannel, returns the related SocketChannel the related SocketChannel



getInetAddress
public InetAddress getInetAddress()(Code)
Returns an InetAddress instance representing the address this socket has connected to. if this socket is connected, the address it is connected to. Anull return signifies no connection has been made.



getInputStream
public InputStream getInputStream() throws IOException(Code)
Answer the socket input stream, to read byte data off the socket. Note, multiple input streams may be created on a single socket. a byte oriented read stream for this socket
throws:
  IOException - if an error occurs creating the stream
See Also:   org.apache.harmony.luni.net.SocketInputStream



getKeepAlive
public boolean getKeepAlive() throws SocketException(Code)
Answer the SO_KEEPALIVE option for this socket. the socket SO_KEEPALIVE option setting
throws:
  SocketException - if an error occurs on the option access



getLocalAddress
public InetAddress getLocalAddress()(Code)
Returns an InetAddress instance representing the local address this socket is bound to. the local address that this socket has bound to



getLocalPort
public int getLocalPort()(Code)
Answer the local port to which the socket is bound. the local port to which the socket is bound



getLocalSocketAddress
public SocketAddress getLocalSocketAddress()(Code)
Answer the local SocketAddress for this socket, or null if the socket is not bound.

This is useful on multihomed hosts. the local socket address




getOOBInline
public boolean getOOBInline() throws SocketException(Code)
Get the state of the SO_OOBINLINE socket option. true if the SO_OOBINLINE is enabled,false otherwise.
throws:
  SocketException - if the socket is closed or the option is invalid.



getOutputStream
public OutputStream getOutputStream() throws IOException(Code)
Answer the socket output stream, for writing byte data on the socket. Note, multiplie output streams may be created on a single socket. OutputStream a byte oriented write stream for this socket
throws:
  IOException - if an error occurs creating the stream
See Also:   org.apache.harmony.luni.net.SocketOutputStream



getPort
public int getPort()(Code)
Returns the number of the remote port this socket is connected to. int the remote port number that this socket has connected to. Areturn of 0 (zero) indicates that there is noconnection in place.



getReceiveBufferSize
public synchronized int getReceiveBufferSize() throws SocketException(Code)
Answer the socket receive buffer size (SO_RCVBUF). socket receive buffer size
throws:
  SocketException - if an error occurs on the option access



getRemoteSocketAddress
public SocketAddress getRemoteSocketAddress()(Code)
Answer the remote SocketAddress for this socket, or null if the socket is not connected. the remote socket address



getReuseAddress
public boolean getReuseAddress() throws SocketException(Code)
Get the state of the SO_REUSEADDR socket option. true if the SO_REUSEADDR is enabled,false otherwise.
throws:
  SocketException - if the socket is closed or the option is invalid.



getSendBufferSize
public synchronized int getSendBufferSize() throws SocketException(Code)
Answer the socket send buffer size (SO_SNDBUF). socket send buffer size
throws:
  SocketException - if an error occurs on the option access



getSoLinger
public int getSoLinger() throws SocketException(Code)
Answer the linger-on-close timeout for this socket (the SO_LINGER value). this socket's SO_LINGER value. A value of -1 willbe returned if the option is not enabled.
throws:
  SocketException - if an error occurs on querying this property



getSoTimeout
public synchronized int getSoTimeout() throws SocketException(Code)
Answer the socket read timeout. The SO_TIMEOUT option, a value of 0 indicates it is disabled and a read operation will block indefinitely waiting for data. the socket read timeout
throws:
  SocketException - if an error occurs on the option access



getTcpNoDelay
public boolean getTcpNoDelay() throws SocketException(Code)
Answer true if the socket is using Nagle's algorithm. The TCP_NODELAY option setting. the socket TCP_NODELAY option setting
throws:
  SocketException - if an error occurs on the option access



getTrafficClass
public int getTrafficClass() throws SocketException(Code)
Get the IP_TOS socket option. the IP_TOS socket option value
throws:
  SocketException - if the option is invalid



isBound
public boolean isBound()(Code)
Return if the socket is bound to a local address and port. true if the socket is bound to a local address,false otherwise.



isClosed
public boolean isClosed()(Code)
Return if the socket is closed. true if the socket is closed, falseotherwise.



isConnected
public boolean isConnected()(Code)
Return if the socket is connected. true if the socket is connected,false otherwise.



isInputShutdown
public boolean isInputShutdown()(Code)
Return if Socket.shutdownInput has been called. true if shutdownInput has beencalled, false otherwise.



isOutputShutdown
public boolean isOutputShutdown()(Code)
Return if Socket.shutdownOutput has been called. true if shutdownOutput has beencalled, false otherwise.



preferIPv4Stack
static boolean preferIPv4Stack()(Code)



sendUrgentData
public void sendUrgentData(int value) throws IOException(Code)
Send the single byte of urgent data on the socket.
Parameters:
  value - the byte of urgent data
exception:
  IOException - when an error occurs sending urgent data



setKeepAlive
public void setKeepAlive(boolean value) throws SocketException(Code)
Set the SO_KEEPALIVE option for this socket.
Parameters:
  value - the socket SO_KEEPALIVE option setting
throws:
  SocketException - if an error occurs setting the option



setOOBInline
public void setOOBInline(boolean oobinline) throws SocketException(Code)
Set the SO_OOBINLINE socket option. When this option is enabled, out of band data is recieved in the normal data stream.
Parameters:
  oobinline - the socket SO_OOBINLINE option setting
throws:
  SocketException - if the socket is closed or the option is invalid.



setPerformancePreferences
public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)(Code)
sets performance preference for connectionTime,latency and bandwidth
Parameters:
  connectionTime - the importance of connect time
Parameters:
  latency - the importance of latency
Parameters:
  bandwidth - the importance of bandwidth



setReceiveBufferSize
public synchronized void setReceiveBufferSize(int size) throws SocketException(Code)
Set the socket receive buffer size.
Parameters:
  size - the buffer size, in bytes
throws:
  SocketException - tf an error occurs while setting the size or the size isinvalid.



setReuseAddress
public void setReuseAddress(boolean reuse) throws SocketException(Code)
Set the SO_REUSEADDR socket option.
Parameters:
  reuse - the socket SO_REUSEADDR option setting
throws:
  SocketException - if the socket is closed or the option is invalid.



setSendBufferSize
public synchronized void setSendBufferSize(int size) throws SocketException(Code)
Set the socket send buffer size.
Parameters:
  size - the buffer size, in bytes
throws:
  SocketException - if an error occurs while setting the size or the size isinvalid.



setSoLinger
public void setSoLinger(boolean on, int timeout) throws SocketException(Code)
Set the SO_LINGER option, with the specified time, in seconds. The SO_LINGER option is silently limited to 65535 seconds.
Parameters:
  on - if linger is enabled
Parameters:
  timeout - the linger timeout value, in seconds
throws:
  SocketException - if an error occurs setting the option



setSoTimeout
public synchronized void setSoTimeout(int timeout) throws SocketException(Code)
Set the read timeout on this socket. The SO_TIMEOUT option, is specified in milliseconds. The read operation will block indefinitely for a zero value.
Parameters:
  timeout - the read timeout value
throws:
  SocketException - if an error occurs setting the option



setSocketImplFactory
public static synchronized void setSocketImplFactory(SocketImplFactory fac) throws IOException(Code)
Specifies the application's socket implementation factory. This may only be executed the once over the lifetime of the application.
Parameters:
  fac - the socket factory to set
exception:
  IOException - thrown if the factory has already been set



setTcpNoDelay
public void setTcpNoDelay(boolean on) throws SocketException(Code)
Set whether the socket is to use Nagle's algorithm. The TCP_NODELAY option setting.
Parameters:
  on - the socket TCP_NODELAY option setting
throws:
  SocketException - if an error occurs setting the option



setTrafficClass
public void setTrafficClass(int value) throws SocketException(Code)
Set the IP_TOS socket option.
Parameters:
  value - the socket IP_TOS setting
throws:
  SocketException - if the socket is closed or the option is invalid.



shutdownInput
public void shutdownInput() throws IOException(Code)
Shutdown the input portion of the socket.
throws:
  IOException - if an error occurs while closing the socket input
throws:
  SocketException - if the socket is closed



shutdownOutput
public void shutdownOutput() throws IOException(Code)
Shutdown the output portion of the socket.
throws:
  IOException - if an error occurs while closing the socket output
throws:
  SocketException - if the socket is closed



startupSocket
void startupSocket(InetAddress dstAddress, int dstPort, InetAddress localAddress, int localPort, boolean streaming) throws IOException(Code)
Creates a stream socket, binds it to the nominated local address/port, then connects it to the nominated destination address/port.
Parameters:
  dstAddress - the destination host address
Parameters:
  dstPort - the port on the destination host
Parameters:
  localAddress - the address on the local machine to bind
Parameters:
  localPort - the port on the local machine to bind
throws:
  IOException - thrown if a error occurs during the bind or connectoperations



toString
public String toString()(Code)
Answers a string containing a concise, human-readable description of the socket. the description



Methods inherited from java.lang.Object
protected Object clone() throws CloneNotSupportedException(Code)(Java Doc)
public boolean equals(Object object)(Code)(Java Doc)
protected void finalize() throws Throwable(Code)(Java Doc)
final public Class<? extends Object> getClass()(Code)(Java Doc)
public int hashCode()(Code)(Java Doc)
final public void notify()(Code)(Java Doc)
final public void notifyAll()(Code)(Java Doc)
public String toString()(Code)(Java Doc)
final public void wait(long millis, int nanos) throws InterruptedException(Code)(Java Doc)
final public void wait(long millis) throws InterruptedException(Code)(Java Doc)
final public void wait() throws InterruptedException(Code)(Java Doc)

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.