0

I'm make simple game(with server) in java. I would like to receive packets from the server to a certain time, but do not know how to solve it.

What is an effective solution?

For example in pseudo:

Thread one:
    tryToGetPacketFromServer(){
          GETPACKET...
    }
Thread two:
    timer(){
     if gettin time of thread one > 5 second;
     print errorr and stop thread one..
    }
staigoun
  • 75
  • 1
  • 7
  • You're looking for a timeout system? What are you using to receive packets? – Vince Dec 21 '14 at 18:29
  • @VinceEmigh I'm looking for a library that will measure time of method and if it exceeds a limit will this metod canceled. – staigoun Dec 21 '14 at 18:31
  • @VinceEmigh i am using `DatagramSocket` class – staigoun Dec 21 '14 at 18:33
  • So yeah, you want the method to block until it reads in a packet. If the method blocks for more than 5 seconds, cancel the method? – Vince Dec 21 '14 at 18:33
  • 3
    possible duplicate of [Adding timeout to DatagramSocket - receive()](http://stackoverflow.com/questions/12363078/adding-timeout-to-datagramsocket-receive) If you don't understand, just call `setSoTimeout` on the datagram socket receiving the packet – Vince Dec 21 '14 at 18:38

0 Answers0