title: iPhone TCP/IP Socket Server/Client Program
body: <p><em>I have read a lot of questions regarding this subject on this website however they didn't quiet answer my question. If you can't be ### about my goal or background skip to the question.</em></p>
  
  <p><strong>My Goal</strong> </p>
  
  <p>Is to build a server that can run on Mac OS X 10.4+ and later, port it to Windows XP/Vista (no idea how to do that yet, but that's a problem for later). </p>
  
  <p>Then let the iPhone be the client that is able to see the computer names that are running the server (through WiFi). The user of the iPhone can then select the computer name to connect to the server on that computer. </p>
  
  <p>After that they can send simple text messages to each other. For example, the iPhone sends 'Knock Knock' and the server responds 'Who is there?'. Or a simple client: 'Ping', server responds 'Pong' will do just fine.</p>
  
  <p><strong>Background</strong> </p>
  
  <p>I have worked with sockets in the past, but only in Visual Basic 6 with the WINSOCKET.dll it was very easy to create a TCP/IP server.</p>
  
  <pre><code>server.host = localhost;
  server.port = 12203;
  server.listen(); 
  </code></pre>
  
  <p>With the client I only needed to do the following to connect.</p>
  
  <pre><code>client.connect(localhost, 12203);
  </code></pre>
  
  <p>There were some callbacks available like connect, close, dataArrival, etc. which I could use to do anything I want.</p>
  
  <p>Perhaps for the iPhone there are libraries written for it, but is it that hard to create this simple application yourself? After doing some research I understand that I have to look in the area of CFNetwork, CFHost, CFSocket, CFStream. </p>
  
  <p><strong>Question</strong></p>
  
  <p>Is there anyone that could guide me to a tutorial or post the code where you have two buttons on the iPhone. [ Start Server ] and [ Connect to Server] where the first will start a TCP/IP server on a certain port and the second connects to it. </p>
  
  <p>After a connection has been made maybe also the code to send a simple 'Ping'-message to the server after the server receives this responds with a 'Pong'-message to the client.</p>
  
  <p>That would really be helpful. But maybe I am asking for to much here.</p>