Rock'em Sock'em Sockets and Tables




CS185c

Chris Pollett

Oct. 18, 2009

Outline

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();
      }
   }
}

Quiz

Which of the following is true?

  1. To handle links clicked in a WebView on Android we can create a subclass of WebViewClient and add an object of this subclass to our WebView using setViewClient.
  2. Phone 7 exposes a socket API which looks like a C Sharp version of the Java Socket API.
  3. LinQ syntax makes use of where from select clauses.

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

Tables Interface Builder

Tables Code

Tables Code