title: Synchronizing clock between client and server programs in c
body: <p>I am working on a project where a server parses audio files, and then tells clients to play certain sections of audio based on a common clock, the server's. In theory we would need a high level of synchronization as the client nodes might be playing audio right beside each other, and all but the smallest of delays may produce a sound offset noticeable by the human ear. I have been trying to find c code examples of how to address this problem and have had little luck.</p>
  
  <p>I have read many of the Wikipedia articles about clock synchronization.</p>
  
  <p><a href="http://en.wikipedia.org/wiki/Clock_synchronization" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Clock_synchronization</a></p>
  
  <p>The above articles lead me to believe PTP would be ideal for our implementation on a local network. But ideally we would like to expand our project to allow for connection over the internet. This lead me to believe NTP would be better. I visited NTP.org but found it difficult to understand, and it seemed like if my applications are on a local network, which isn't connected to the internet, I couldn't use NTP at all. But then I found this post:</p>
  
  <p><a href="https://stackoverflow.com/questions/5642946/small-footprint-clock-synchronization-without-ntp">Small footprint clock synchronization without NTP</a></p>
  
  <p>And Seth Robertson's response lead me to believe I was mistaken.</p>
  
  <p><em>you can get synchronized to a chosen system's clock using a few configuration file lines (four lines on each client, five lines on the server).</em></p>
  
  <p>The problem is, he didn't show those lines of code, or point me to a place where I could view code that handles these problems. </p>
  
  <p>I've been looking around stackoverflow, and found many similar questions, but none that gave satisfactory answers. </p>
  
  <p>So, after a wall of text (sorry about that, the stack overflow question advice said to be very specific and explain the research I had done before asking a question), I would like to succinctly state my question, and hopefully someone can help me out:</p>
  
  <p><em>In a client/server software model, how can I maintain an accurate clock synchronization within the software to allow event execution based on time?</em></p>
  
  <p>Currently our group is using UDP, but we are willing to change if necessary.</p>
  
  <p>Thanks for any help.</p>
  
  <p>EDIT: I understand that I need to maintain a clock sync, the question is, HOW do I do this in software. I'm looking for example code, or a hyperlink to a place where I can find sample code on this subject.
  ENDEDIT</p>