本文整理匯總了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();
}