Java Doc for DatagramSocket.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.DatagramSocket

All known Subclasses:   java.net.MulticastSocket,
DatagramSocket
public class DatagramSocket (Code)
This class models a socket for sending & receiving datagram packets.
See Also:   DatagramPacket


Field Summary
 InetAddressaddress
    
static  DatagramSocketImplFactoryfactory
    
 DatagramSocketImplimpl
    
 booleanisBound
    
 intport
    

Constructor Summary
public  DatagramSocket()
     Constructs a datagram socket, bound to any available port on the localhost.
public  DatagramSocket(int aPort)
     Answers a datagram socket, bound to the nominated port on the localhost.
public  DatagramSocket(int aPort, InetAddress addr)
     Constructs a datagram socket, bound to the nominated localhost/port.
protected  DatagramSocket(DatagramSocketImpl socketImpl)
     Constructs a DatagramSocket using the specified DatagramSocketImpl.
public  DatagramSocket(SocketAddress localAddr)
     Constructs a DatagramSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.

Method Summary
public  voidbind(SocketAddress localAddr)
     Bind the DatagramSocket to the nominated local host/port.
 voidcheckClosedAndBind(boolean bind)
    
 voidcheckListen(int aPort)
     Sent prior to attempting to bind the socket, check that the port is within the valid port range and verify with the security manager that the port may be bound by the current context.
public  voidclose()
     Close the socket.
public  voidconnect(InetAddress anAddress, int aPort)
     Connect the datagram socket to a remote host and port.
public  voidconnect(SocketAddress remoteAddr)
     Connect the datagram socket to a remote host and port.
synchronized  voidcreateSocket(int aPort, InetAddress addr)
    
public  voiddisconnect()
     'Disconnect' the datagram socket from a remote host and port.
public  booleangetBroadcast()
     Get the state of the SO_BROADCAST socket option.
public  DatagramChannelgetChannel()
    
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  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  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 synchronized  intgetSoTimeout()
     Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds.
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 synchronized  voidreceive(DatagramPacket pack)
     Receive on this socket into the packet argument.
public  voidsend(DatagramPacket pack)
     Send the packet on this socket.
public  voidsetBroadcast(boolean broadcast)
     Set the SO_BROADCAST socket option.
public static synchronized  voidsetDatagramSocketImplFactory(DatagramSocketImplFactory fac)
     Specifies the application's socket implementation factory.
public synchronized  voidsetReceiveBufferSize(int size)
     Set the socket receive buffer size.
Parameters:
  size - the buffer size, in bytes.
public  voidsetReuseAddress(boolean reuse)
     Set the SO_REUSEADDR socket option.
public synchronized  voidsetSendBufferSize(int size)
     Set the socket send buffer size.
Parameters:
  size - the buffer size, in bytes.
public synchronized  voidsetSoTimeout(int timeout)
     Set the SO_RCVTIMEOUT to timeout, in milliseconds.
public  voidsetTrafficClass(int value)
     Set the IP_TOS socket option.

Field Detail
address
InetAddress address(Code)



factory
static DatagramSocketImplFactory factory(Code)



impl
DatagramSocketImpl impl(Code)



isBound
boolean isBound(Code)



port
int port(Code)




Constructor Detail
DatagramSocket
public DatagramSocket() throws SocketException(Code)
Constructs a datagram socket, bound to any available port on the localhost.
throws:
  SocketException - if a problem occurs creating or binding the socket



DatagramSocket
public DatagramSocket(int aPort) throws SocketException(Code)
Answers a datagram socket, bound to the nominated port on the localhost.
Parameters:
  aPort - the port to bind on the localhost
throws:
  SocketException - if a problem occurs creating or binding the socket



DatagramSocket
public DatagramSocket(int aPort, InetAddress addr) throws SocketException(Code)
Constructs a datagram socket, bound to the nominated localhost/port.
Parameters:
  aPort - the port on the localhost to bind
Parameters:
  addr - the address on the multihomed localhost to bind
throws:
  SocketException - if a problem occurs creating or binding the socket



DatagramSocket
protected DatagramSocket(DatagramSocketImpl socketImpl)(Code)
Constructs a DatagramSocket using the specified DatagramSocketImpl. The DatagramSocket is not bound.
Parameters:
  socketImpl - the DatagramSocketImpl to use



DatagramSocket
public DatagramSocket(SocketAddress localAddr) throws SocketException(Code)
Constructs a DatagramSocket bound to the host/port specified by the SocketAddress, or an unbound DatagramSocket if the SocketAddress is null.
Parameters:
  localAddr - the local machine address and port to bind to
throws:
  IllegalArgumentException - if the SocketAddress is not supported
throws:
  SocketException - if a problem occurs creating or binding the socket




Method Detail
bind
public void bind(SocketAddress localAddr) throws SocketException(Code)
Bind the DatagramSocket 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:
  SocketException - if the socket is already bound, or a problem occurs duringthe bind



checkClosedAndBind
void checkClosedAndBind(boolean bind) throws SocketException(Code)



checkListen
void checkListen(int aPort)(Code)
Sent prior to attempting to bind the socket, check that the port is within the valid port range and verify with the security manager that the port may be bound by the current context.
Parameters:
  aPort - the port on the localhost that is to be bound



close
public void close()(Code)
Close the socket.



connect
public void connect(InetAddress anAddress, int aPort)(Code)
Connect the datagram socket to a remote host and port. The host and port are validated, thereafter the only validation on send() and receive() is that the packet address/port matches the connected target.
Parameters:
  anAddress - the target address
Parameters:
  aPort - the target port



connect
public void connect(SocketAddress remoteAddr) throws SocketException(Code)
Connect the datagram socket to a remote host and port. The host and port are validated, thereafter the only validation on send() and receive() is that the packet address/port matches the connected target.
Parameters:
  remoteAddr - the target address and port
exception:
  SocketException - if a problem occurs during the connect



createSocket
synchronized void createSocket(int aPort, InetAddress addr) throws SocketException(Code)



disconnect
public void disconnect()(Code)
'Disconnect' the datagram socket from a remote host and port. This method may be called on an unconnected socket.



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



getChannel
public DatagramChannel getChannel()(Code)
if DatagramSocket is created by a DatagramChannel, returns the related DatagramChannel the related DatagramChannel if any



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.



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



getLocalPort
public int getLocalPort()(Code)
Answer the local port to which the socket is bound. int 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




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 -1 indicates that there is no connectionin place.



getReceiveBufferSize
public synchronized int getReceiveBufferSize() throws SocketException(Code)
Answer the socket receive buffer size (SO_RCVBUF). int socket receive buffer size
exception:
  SocketException - when an error occurs



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). int socket send buffer size
exception:
  SocketException - when an error occurs



getSoTimeout
public synchronized int getSoTimeout() throws SocketException(Code)
Answer the socket receive timeout (SO_RCVTIMEOUT), in milliseconds. Zero implies the timeout is disabled. int socket receive timeout
exception:
  SocketException - when an error occurs



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.



receive
public synchronized void receive(DatagramPacket pack) throws IOException(Code)
Receive on this socket into the packet argument. This method blocks until a packet is received or, if a timeout has been defined, the timeout period expires. If this is a connected socket, the packet host/port are compared to the connection host/port otherwise the security manager if present is queried whether the packet host/port is acceptable. Any packets from unacceptable origins will be silently discarded. The packet fields are set according to the data received. If the received data is longer than the packet buffer, it is truncated.
Parameters:
  pack - the DatagramPacket to receive data into
exception:
  java.io.IOException - If a receive error occurs.



send
public void send(DatagramPacket pack) throws IOException(Code)
Send the packet on this socket. The packet must satisfy the security policy before it may be sent.
Parameters:
  pack - the DatagramPacket to send
exception:
  java.io.IOException - If a send error occurs.



setBroadcast
public void setBroadcast(boolean broadcast) throws SocketException(Code)
Set the SO_BROADCAST socket option.
Parameters:
  broadcast - the socket SO_BROADCAST option setting
throws:
  SocketException - if the socket is closed or the option is invalid.



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



setReceiveBufferSize
public synchronized void setReceiveBufferSize(int size) throws SocketException(Code)
Set the socket receive buffer size.
Parameters:
  size - the buffer size, in bytes. Must be at least one byte.
exception:
  java.net.SocketException - If 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. Must be at least one byte.
exception:
  java.net.SocketException - If an error occurs while setting the size or the size isinvalid.



setSoTimeout
public synchronized void setSoTimeout(int timeout) throws SocketException(Code)
Set the SO_RCVTIMEOUT to timeout, in milliseconds. The receive timeout defines the period a socket will block waiting to receive data, before throwing an InterruptedIOException.
Parameters:
  timeout - the timeout period, in milliseconds
exception:
  java.net.SocketException - If an error occurs while setting the timeout or the periodis invalid.



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.



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.