/** * Closes this datagram socket. * * <p>Any thread currently blocked in {@link #receive} upon this socket will throw a {@link * SocketException}. * * <p>If this socket has an associated channel then the channel is closed as well. * * @revised 1.4 * @spec JSR-51 */ public void close() { synchronized (closeLock) { if (isClosed()) return; impl.close(); closed = true; } }
@Override protected void finalize() throws Throwable { try { if (guard != null) { guard.warnIfOpen(); } close(); } finally { super.finalize(); } }
/** * Disconnects the socket. If the socket is closed or not connected, then this method has no * effect. * * @see #connect */ public void disconnect() { synchronized (this) { if (isClosed()) return; if (connectState == ST_CONNECTED) { impl.disconnect(); } connectedAddress = null; connectedPort = -1; connectState = ST_NOT_CONNECTED; } }
void createImpl() throws SocketException { if (impl == null) { if (factory != null) { impl = factory.createDatagramSocketImpl(); checkOldImpl(); } else { boolean isMulticast = (this instanceof MulticastSocket) ? true : false; impl = DefaultDatagramSocketImplFactory.createDatagramSocketImpl(isMulticast); checkOldImpl(); } } // creates a udp socket impl.create(); created = true; }
@Override public PacketWritestream write(Buffer data) { datagramSocket.send(data, port, host, this); return this; }