Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

delay between commands

 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am writing a program that is delivering bytes over a socket to a machine that responds to commands. The machine needs at least 100 milliseconds between commands to execute properly. I have one sequence that is sending too quickly. How do I build in a delay of 200 milliseconds between commands?

thanks!
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Let's move this topic to the sockets forum. Please let me know if you are using something more complex than the socket layer.

Henry
 
Paul Clapham
Sheriff
Posts: 21892
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The way to get the JVM to pause for a certain length of time is to use the Thread.sleep(int) method, passing it the number of milliseconds you want it to pause for. Does that answer your question, or was it more complicated than that?
 
Guillermo Ishi
Ranch Hand
Posts: 789
C++ Linux Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are three strategies that come to mind. Best would usually be have the machine that responds to commands cue the commands, preferably while it's executing previous commands, then it can finish whenever and ignore the other machine. That's how a printer works. Second you could have the machine accepting commands send something back when it's finished, to say it's ready for another command. Third the machine sending commands could poll the one accepting commands -- similar to the second idea but initiated by the other machine. Also there should be some communication using checksums so the machine knows it received all the commands and the right commands. And it should be able to request the commands be sent again if there was a problem. Delays is a sloppy idea unless it something trivial.
 
Scott A Burch
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thread.sleep is what I was looking for ... it's purpose is for pacing. Just read the Oracle doc on the subject. Thanks to all for the suggestions.
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I agree with Guillermo. A delay should work, but it is not guaranteed to work.

Keep in mind that a network is not guaranteed to keep that spacing... if the connection has to traverse multiple switches, routers, and firewalls, it is definitely unlikely that the spacing will be maintained.

Henry
 
Opportunity is missed by most people because it is dressed in overalls and looks like work - Edison. Tiny ad:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!