KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > java > net > DatagramSocket

java.net
Class DatagramSocket

java.lang.Object
  extended by java.net.DatagramSocket
Direct Known Subclasses:
MulticastSocket
See Also:
Top Examples, Source Code, DatagramPacket, DatagramChannel

public void bind(SocketAddress addr)
          throws SocketException
See Also:
IllegalArgumentException, SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void close()
See Also:
SocketException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void connect(InetAddress address,
                    int port)
See Also:
receive(java.net.DatagramPacket), send(java.net.DatagramPacket), disconnect(), SecurityException, IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void connect(SocketAddress addr)
             throws SocketException
See Also:
connect(java.net.InetAddress, int), IllegalArgumentException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DatagramSocket()
               throws SocketException
See Also:
SecurityManager.checkListen(int), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DatagramSocket(int port)
               throws SocketException
See Also:
SecurityManager.checkListen(int), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DatagramSocket(int port,
                      InetAddress laddr)
               throws SocketException
See Also:
SecurityManager.checkListen(int), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


protected DatagramSocket(DatagramSocketImpl impl)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DatagramSocket(SocketAddress bindaddr)
               throws SocketException
See Also:
SecurityManager.checkListen(int), SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void disconnect()
See Also:
connect(java.net.InetAddress, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getBroadcast()
                     throws SocketException
See Also:
setBroadcast(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public DatagramChannel getChannel()
See Also:
DatagramChannel.open
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public InetAddress getInetAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public InetAddress getLocalAddress()
See Also:
SecurityManager.checkConnect(java.lang.String, int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getLocalPort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public SocketAddress getLocalSocketAddress()
See Also:
bind(SocketAddress), getLocalPort(), getLocalAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getPort()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getReceiveBufferSize()
                         throws SocketException
See Also:
setReceiveBufferSize(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public SocketAddress getRemoteSocketAddress()
See Also:
connect(SocketAddress), getPort(), getInetAddress()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean getReuseAddress()
                        throws SocketException
See Also:
setReuseAddress(boolean)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getSendBufferSize()
                      throws SocketException
See Also:
setSendBufferSize(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getSoTimeout()
                 throws SocketException
See Also:
setSoTimeout(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public int getTrafficClass()
                    throws SocketException
See Also:
setTrafficClass(int)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1310]Different behaviour of getTrafficClass on different platform
By Matt Crawford on 2005/02/17 15:53:24  Rate
Under J2SE 1.4.2, this call is ignored on some Linux systems and honored on others, even with what seem to be very similar kernel version. On MacOS 10.3 it throws a java.net.SocketException: Invalid argument. 
 


public boolean isBound()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isClosed()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public boolean isConnected()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void receive(DatagramPacket p)
             throws IOException
See Also:
DatagramSocket, IllegalBlockingModeException, PortUnreachableException, SocketTimeoutException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void send(DatagramPacket p)
          throws IOException
See Also:
SecurityManager.checkConnect(java.lang.String, int), SecurityManager.checkMulticast(InetAddress), IllegalBlockingModeException, PortUnreachableException, SecurityException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1427]Sent data over UDP socket
By born2snipe on 2005/05/13 16:28:12  Rate
// you must know your host IP and the port of the packets need to be sent 
 InetAddress host = InetAddress.getByName ( "http://www.kickjava.com" ) ; 
 int port = 27015; 
  
  
 // data that you want sent to the host 
 byte buf [  ]  = new byte [ 1024 ] ; 
 DatagramPacket packet = new DatagramPacket ( buf,buf.length,host,port ) ; 
  
  
 // your UDP socket that will send the packet 
 DatagramSocket udp = new DatagramSocket (  ) ; 
  
  
 // send the packet to the host  ( throws IOException )  
 upd.send ( packet ) ;


public void setBroadcast(boolean on)
                  throws SocketException
See Also:
getBroadcast()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public static void setDatagramSocketImplFactory(DatagramSocketImplFactory fac)
                                         throws IOException
See Also:
SecurityManager.checkSetFactory(), DatagramSocketImplFactory.createDatagramSocketImpl(), SecurityException, SocketException
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setReceiveBufferSize(int size)
                          throws SocketException
See Also:
getReceiveBufferSize(), IllegalArgumentException, receive(DatagramPacket)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setReuseAddress(boolean on)
                     throws SocketException
See Also:
isClosed(), isBound(), bind(SocketAddress), getReuseAddress(), MulticastSocket
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setSendBufferSize(int size)
                       throws SocketException
See Also:
getSendBufferSize(), IllegalArgumentException, send(DatagramPacket)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setSoTimeout(int timeout)
                  throws SocketException
See Also:
getSoTimeout()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setTrafficClass(int tc)
                     throws SocketException
See Also:
getTrafficClass()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  

Popular Tags