iPhone Networking




CS185c

Chris Pollett

Mar 14, 2012

Outline

Networking on the iPhone

Some UIWebView and UiWebViewDelegate methods

Getting the Response into Data

Creating CFSockets

Description of Our App

Code of Server we will connect to

import java.io.*;
import java.net.*;

public final class MyServer extends Thread
{
   private static final int PORT=8889;
   private static final int NUM_CONNECT=1;

   private MyServer() {}

   public static void main(String args[])
   {
      MyServer myServer = new MyServer();
      if(myServer !=null) {myServer.start();}
   }

   public void run()
   {
      try
      {
         ServerSocket server = new ServerSocket(PORT, NUM_CONNECT);
         Socket client = server.accept();

         BufferedReader reader = new BufferedReader(
            new InputStreamReader(client.getInputStream()));

         PrintWriter writer = new PrintWriter(new BufferedWriter(
            new OutputStreamWriter(client.getOutputStream())));

         String line = reader.readLine();

         System.out.println("Hello"+line);

         if(line.equals("HELLO"))
         {
            writer.print("Chicago:New York:San Francisco:");
            writer.print("Chicago:New York:San Francisco:");
            writer.println("Chicago:New York:San Francisco\n");
         }
         writer.flush();
      }
      catch(IOException ie)
      {
         ie.printStackTrace();
      }
   }
}

Set up the socket

Set up the address to connect to:

Set up our Run Loop to wait for the connection to establish

Our Callback Function

Using Streams

Tables

Table Interface Builder

Table Code

Tables Code