Android Open Source - OHC-android Socket_timeout






From Project

Back to project page OHC-android.

License

The source code is released under:

MIT License

If you think the Android project OHC-android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package io.openhc.ohc.skynet;
//from w w w.j a  v a 2  s .com
import java.net.DatagramSocket;
import java.util.Timer;
import java.util.TimerTask;
import java.util.logging.Level;

import io.openhc.ohc.OHC;

//Closes a socket after a given amount of time
public class Socket_timeout extends TimerTask
{
  private final Socket_provider supplier;
  private final long timeout;

  public Socket_timeout(Socket_provider supplier, long timeout)
  {
    this.supplier = supplier;
    this.timeout = timeout;
  }

  public void start()
  {
    Timer t = new Timer();
    t.schedule(this, this.timeout);
  }

  public void run()
  {
    DatagramSocket socket = this.supplier.get_socket();
    try
    {
      socket.close();
      OHC.logger.log(Level.INFO, "Closing socket: " + socket.toString());
    }
    catch(Exception ex)
    {
      OHC.logger.log(Level.INFO, String.format("Closing socket %s : %s", socket.toString(), ex.getMessage()), ex);
    }
  }

  public interface Socket_provider
  {
    public DatagramSocket get_socket();
  }
}




Java Source Code List

io.openhc.ohc.ApplicationTest.java
io.openhc.ohc.OHC.java
io.openhc.ohc.OHC_ui.java
io.openhc.ohc.basestation.Basestation.java
io.openhc.ohc.basestation.device.Device.java
io.openhc.ohc.basestation.device.Field.java
io.openhc.ohc.basestation.rpc.Base_rpc.java
io.openhc.ohc.logging.OHC_Logger.java
io.openhc.ohc.skynet.Broadcaster.java
io.openhc.ohc.skynet.Network.java
io.openhc.ohc.skynet.Receiver.java
io.openhc.ohc.skynet.Sender.java
io.openhc.ohc.skynet.Socket_timeout.java
io.openhc.ohc.skynet.transaction.Transaction_generator.java
io.openhc.ohc.ui.Field_adapter.java
io.openhc.ohc.ui.input.filter.Input_filter_float.java
io.openhc.ohc.ui.input.filter.Input_filter_int.java
io.openhc.ohc.ui.input.filter.Input_filter_string.java