本文整理汇总了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();
}
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}