title: Which protocol to choose for a turn-based game server
body: <p>I am writing a game server for a turn-based game in Java.
  These are the facts:</p>
  
  <ul>
  <li>The speed of the game is slow, so clients need to send data let's say every 8 seconds, and that data is most of the time only a small incremental update (a few dozen bytes), aside from situations like join of the game or list available games etc.</li>
  <li>The server must support a large number of players which, let's say 1000, which play one of a few hundred games</li>
  <li>When player makes a turn, other players in the same game must be notified of the move. The maximum number of players in the game is around 10</li>
  </ul>
  
  <p>First of all, I excluded UDP from my option list as I need a reliable protocol because in rare situations I really need to send some data which cannot fit in one packet and I don't want to bother with merging packets and similar things, tracking the order of the arrived packages and other low-level stuff.   </p>
  
  <p>So the dilemma is whether to use TCP or HTTP.</p>
  
  <p><strong>TCP attempt #1</strong></p>
  
  <p>The connection from the client to the server (and vice-versa) is opened all the time. This way, when a player makes a move, the server can easily notify other players in the game which move was made. The main thing which bothers me with this approach is whether it is advisable or even possible to have as much as 1000 connections and sockets opened all the time?</p>
  
  <p><strong>TCP attempt #2</strong></p>
  
  <p>The alternative which I thought of is, to use to establish a seperate connection/socket on every request from a client. A client would open a connection, send some small data to the server and close that connection. With this approach, I can have a fixed size thread pool of let's say 10 and process client's requests in each thread separately so that there is at most 10 connectinos/sockets opened at any time. But there are two things which bothers me with this approach:</p>
  
  <ol>
  <li>expensiveness of opening/closing the connection to the client</li>
  <li>the way of notifying other players in the game, since the connection to them is most probably closed. Each of them should in that case "poll" server for the update let's say every one second.</li>
  </ol>
  
  <p>What is the cost of establishing a TCP socket/connection? Is this an expensive operation or this is done in only a few ms (or less)?</p>
  
  <p><strong>HTTP</strong></p>
  
  <ol>
  <li>Would there be a lot of overhead if
  I would be sending a new GET/POST
  just to send a few bytes?</li>
  <li>Can I keep 1000 HTTP connections to
  clients simultaneously and then use
  AJAX or similar things to reduce
  overhead? In that case, would 1000
  simultaneous connections pose a
  significant problem regarding
  bandwidth/performance?</li>
  </ol>
  
  <p>I am opened to suggestions/advice of any kind.</p>