当前位置: 首页>>代码示例>>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;未经允许,请勿转载。