當前位置: 首頁>>代碼示例>>Java>>正文


Java DatagramSocket.isClosed方法代碼示例

本文整理匯總了Java中java.net.DatagramSocket.isClosed方法的典型用法代碼示例。如果您正苦於以下問題:Java DatagramSocket.isClosed方法的具體用法?Java DatagramSocket.isClosed怎麽用?Java DatagramSocket.isClosed使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在java.net.DatagramSocket的用法示例。


在下文中一共展示了DatagramSocket.isClosed方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: closeSilently

import java.net.DatagramSocket; //導入方法依賴的package包/類
/** close things if not null, for use in finally blocks, swallows exceptions */
public static void closeSilently(final DatagramSocket socket) {
    if (socket != null && !socket.isClosed()) {
        // does not throw
        socket.close();
    }
}
 
開發者ID:archos-sa,項目名稱:aos-FileCoreLibrary,代碼行數:8,代碼來源:IOUtils.java

示例2: closeSocket

import java.net.DatagramSocket; //導入方法依賴的package包/類
/**
 * Closes the specified DatagramSocket
 */
protected boolean closeSocket(DatagramSocket socket, boolean removeFromList)
{
    this.logDebug("closeSocket: " + socket);

    if (null == socket)
    {
        return false;
    }
    else
    {
        boolean flag = false;

        if (!socket.isClosed())
        {
            socket.close();
            flag = true;
        }

        if (removeFromList)
        {
            this.socketList.remove(socket);
        }

        return flag;
    }
}
 
開發者ID:Notoh,項目名稱:DecompiledMinecraft,代碼行數:30,代碼來源:RConThreadBase.java

示例3: getInfo

import java.net.DatagramSocket; //導入方法依賴的package包/類
String getInfo(DatagramSocket soc) {
    if (soc == null) {
        return null;
    }

    return "localPort: " + soc.getLocalPort()
            + "; localAddress: " + soc.getLocalAddress()
            + "; remotePort: " + soc.getPort()
            + "; remoteAddress: " + soc.getInetAddress()
            + "; isClosed: " + soc.isClosed()
            + "; isBound: " + soc.isBound();
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:13,代碼來源:ReuseAddressTest.java

示例4: start

import java.net.DatagramSocket; //導入方法依賴的package包/類
@Override
public void start() {
    final DatagramSocket udpSocket = packetProvider.getUdpSocket();

    sendThread = new Thread(AudioManagerImpl.AUDIO_THREADS, () ->
    {
        long lastFrameSent = System.currentTimeMillis();
        while (!udpSocket.isClosed() && !sendThread.isInterrupted()) {
            try {
                boolean changeTalking = (System.currentTimeMillis() - lastFrameSent) > OPUS_FRAME_TIME_AMOUNT;
                DatagramPacket packet = packetProvider.getNextPacket(changeTalking);

                if (packet != null)
                    udpSocket.send(packet);
            } catch (NoRouteToHostException e) {
                packetProvider.onConnectionLost();
            } catch (SocketException e) {
                //Most likely the socket has been closed due to the audio connection be closed. Next iteration will kill loop.
            } catch (Exception e) {
                AudioConnection.LOG.error("Error while sending udp audio data", e);
            } finally {
                long sleepTime = (OPUS_FRAME_TIME_AMOUNT) - (System.currentTimeMillis() - lastFrameSent);
                if (sleepTime > 0) {
                    try {
                        Thread.sleep(sleepTime);
                    } catch (InterruptedException e) {
                        //We've been asked to stop.
                        Thread.currentThread().interrupt();
                    }
                }
                if (System.currentTimeMillis() < lastFrameSent + 60) // If the sending didn't took longer than 60ms (3 times the time frame)
                {
                    lastFrameSent += OPUS_FRAME_TIME_AMOUNT; // increase lastFrameSent
                } else {
                    lastFrameSent = System.currentTimeMillis(); // else reset lastFrameSent to current time
                }
            }
        }
    });
    sendThread.setUncaughtExceptionHandler((thread, throwable) ->
    {
        JDALogger.getLog(DefaultSendSystem.class).error("Uncaught exception in audio send thread", throwable);
        start();
    });
    sendThread.setDaemon(true);
    sendThread.setName(packetProvider.getIdentifier() + " Sending Thread");
    sendThread.setPriority(Thread.MAX_PRIORITY);
    sendThread.start();
}
 
開發者ID:GoldRenard,項目名稱:JuniperBotJ,代碼行數:50,代碼來源:AudioSendFactory.java

示例5: start

import java.net.DatagramSocket; //導入方法依賴的package包/類
@Override
public void start()
{
    final DatagramSocket udpSocket = packetProvider.getUdpSocket();


    sendThread = new Thread(AudioManager.AUDIO_THREADS, packetProvider.getIdentifier() + " Sending Thread")
    {
        @Override
        public void run()
        {
            long lastFrameSent = System.currentTimeMillis();
            while (!udpSocket.isClosed() && !sendThread.isInterrupted())
            {
                try
                {
                    boolean changeTalking = (System.currentTimeMillis() - lastFrameSent) > OPUS_FRAME_TIME_AMOUNT;
                    DatagramPacket packet = packetProvider.getNextPacket(changeTalking);

                    if (packet != null)
                        udpSocket.send(packet);
                }
                catch (NoRouteToHostException e)
                {
                    packetProvider.onConnectionLost();
                }
                catch (SocketException e)
                {
                    //Most likely the socket has been closed due to the audio connection be closed. Next iteration will kill loop.
                }
                catch (Exception e)
                {
                    AudioConnection.LOG.log(e);
                }
                finally
                {

                    long sleepTime = (OPUS_FRAME_TIME_AMOUNT) - (System.currentTimeMillis() - lastFrameSent);
                    if (sleepTime > 0)
                    {
                        try
                        {
                            Thread.sleep(sleepTime);
                        }
                        catch (InterruptedException e)
                        {
                            //We've been asked to stop.
                            Thread.currentThread().interrupt();
                        }
                    }
                    if (System.currentTimeMillis() < lastFrameSent + 60) // If the sending didn't took longer than 60ms (3 times the time frame)
                    {
                        lastFrameSent += OPUS_FRAME_TIME_AMOUNT; // increase lastFrameSent
                    }
                    else
                    {
                        lastFrameSent = System.currentTimeMillis(); // else reset lastFrameSent to current time
                    }
                }
            }
        }
    };
    sendThread.setPriority((Thread.NORM_PRIORITY + Thread.MAX_PRIORITY) / 2);
    sendThread.setDaemon(true);
    sendThread.start();
}
 
開發者ID:DV8FromTheWorld,項目名稱:JDA-Audio,代碼行數:67,代碼來源:DefaultSendSystem.java


注:本文中的java.net.DatagramSocket.isClosed方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。