iPhone Networking




CS175

Chris Pollett

Oct 27, 2014

Outline

Compiling Cinequest

Networking on the iPhone

Some UIWebView and UiWebViewDelegate methods

Quiz

Which of the following is true?

  1. The Link layer is the TCP/IP layer most responsible for making connections to a port on a device at a given IP address.
  2. We used the class ConnectivityManager in our Android applications to make a socket connection to an IP address at a given port.
  3. HttpURLConnection can be used to open a connection to a web server and make an HTTP request for a web page it.

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