// kill it with fire! public boolean close() { if (!socket.isClosed() || socket.isConnected()) { socket.close(); return true; } return false; }
private void HandleError() { if (socket.isConnected()) { return; } receiveThreadFinish = true; socket.close(); }
/** * Forces the instant sending of a packet, ignoring the present packet queue. * * @param packet */ public void forceInstantSend(DatagramPacket packet) { if (m_socket.isConnected() == true && !interrupted()) { try { m_socket.send(packet); m_packetsSent++; } catch (Exception e) { m_socket.disconnect(); } } }
/** stop the UDP server, clean up and delete its reference. */ public void dispose() { isRunning = false; _myThread = null; if (_myDatagramSocket != null) { if (_myDatagramSocket.isConnected()) { Logger.printDebug("UdpServer.dispose()", "disconnect()"); _myDatagramSocket.disconnect(); } Logger.printDebug("UdpServer.dispose()", "close()"); _myDatagramSocket.close(); _myDatagramSocket = null; Logger.printDebug("UdpServer.dispose()", "Closing unicast datagram socket."); } }
/** * A synchronized function for closing the UPD socket. It prevents the situation in which both the * listener thread and the GUI thread close the socket at the same time. */ private synchronized void closeSocket() { if (ds != null) { if (ds.isConnected()) { ds.disconnect(); } if (!ds.isClosed()) { ds.close(); } ds = null; if (Debug.SHOW_PROXY_VEHICLE_DEBUG_MSG) { System.err.println("The UDP socket is closed."); } } }
/** Checks the queue for packets waiting to be sent, and sends any that are in waiting. */ public void run() { while (m_socket.isConnected() == true && !interrupted()) { try { if (m_highPriorityPackets.isEmpty() == false) { m_socket.send(m_highPriorityPackets.remove(0)); m_packetsSent++; Thread.sleep(1); } else if (m_packets.isEmpty() == false) { m_socket.send(m_packets.remove(0)); m_packetsSent++; Thread.sleep(2); } else { Thread.sleep(5); } } catch (Exception e) { m_socket.disconnect(); } } }
/** @return True if the connection to the SS server is still active */ public boolean isConnected() { return m_socket.isConnected(); }
public void closeSocket() { // s4s: add by snmp4sdn, because in junit test, occurs // "java.net.BindException: Address already in use: Cannot bind" if (dSocket == null) return; if (dSocket.isConnected()) dSocket.disconnect(); dSocket.close(); }
public void close() { if (socket != null && socket.isConnected()) { socket.close(); } }
public boolean isConnected() { if (socket != null) return socket.isConnected(); else return false; }