CS175
Chris Pollett
Oct 27, 2014
1) Execute the following command android list targets This should give a list of available targets to compile Cinequest to Pick a recent one say android-19, then do android update project --target android-19 --path . --subprojects for each of the following directories facebook/ JavaCommon/ Android/ 2) Navigate to Android/ using terminal and execute the following commands, ant clean ant debug install adb shell am start -n edu.sjsu.cinequest/.HomeActivity
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:
(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[_window makeKeyAndVisible];
CGRect bounds = [[UIScreen mainScreen ] applicationFrame];
UIWebView *webView = [[UIWebView alloc] initWithFrame:bounds];
webView.scalesPageToFit = YES;
[_window addSubview:webView];
NSURL *url = [NSURL URLWithString:@"http://www.pollett.org"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];
[webView loadRequest:request];
return YES;
}
webView.delegate = myDelegate;
Which of the following is true?
NSData *myData = [NSData dataWithContentsOfURL: [NSURL URLWithString: @"http://web_service_url"]];
UIImage *image = [UIImage imageWithData: myData];
NSString *string = [NSString stringWithFormat:@"%.*s", [myData length], [myData bytes]];
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();
}
}
}
CFSocketContext context = { 0, msg, NULL, NULL, NULL };
CFSocketRef client = CFSocketCreate(NULL, PF_INET, SOCK_STREAM, IPPROTO_TCP,
kCFSocketConnectCallBack, (CFSocketCallBack)ConnectCallBack, &context);
struct CFSocketContext {
CFIndex version; // must be 0
void *info; // data to send
CFAllocatorRetainCallBack retain; // callback called when do CFRetain, CFRelease,CFCopy
CFAllocatorReleaseCallBack release;
CFAllocatorCopyDescriptionCallBack copyDescription;
};
CFSocketRef CFSocketCreate ( CFAllocatorRef allocator, SInt32 protocolFamily, //PF_INET is IPv4 SInt32 socketType, SInt32 protocol, CFOptionFlags callBackTypes, //when we want to be called back CFSocketCallBack callout, //our callback const CFSocketContext *context );
struct sockaddr_in theName;
struct hostent *hp;
CFDataRef addressData;
theName.sin_port = htons(8889);
theName.sin_family = AF_INET; //what kind in internet addresses to use; want IP
hp = gethostbyname("pollett.org");
if( hp == NULL ) {
return;
}
memcpy( &theName.sin_addr.s_addr, hp->h_addr_list[0], hp->h_length );
addressData = CFDataCreate( NULL, (UInt8 *)&theName, (CFIndex)sizeof( struct sockaddr_in ) );
CFSocketConnectToAddress(client, addressData, 1); //connect; 1 second timeout CFRunLoopSourceRef sourceRef = CFSocketCreateRunLoopSource(kCFAllocatorDefault, client, 0); CFRunLoopAddSource(CFRunLoopGetCurrent(), sourceRef, kCFRunLoopCommonModes); CFRelease(sourceRef); CFRunLoopRun();
CFSocketNativeHandle sock;
UInt8 buffer[1024];
void ConnectCallBack(
CFSocketRef socket,
CFSocketCallBackType type,
CFDataRef address,
const void *data,
void *info)
{
char *msg = info;
NSLog(@"%s\n", msg);
sock = CFSocketGetNative(socket);
send(sock, msg, strlen(msg)+1, 0);
recv(sock, buffer, sizeof(buffer), 0);
NSLog(@"Got: %s \n", buffer);
CFRunLoopStop(CFRunLoopGetCurrent()); //return execution to our program
return;
}
CFReadStreamRef readStream = NULL; CFWriteStreamRef writeStream = NULL; CFStreamCreatePairWithSocket(kCFAllocatorDefault, sock, &readStream, &writeStream);
NSOutputStream *networkOutputStream = (NSOutputStream *) writeStream; NSInputStream *networkInputStream =(NSInputStream *) readStream;and then work in Objective-C land.