CSE 660 Lab 7. Submitted by: Arumugam Thendramil Pavai. 1)Simple Remote Calculator. Server is created using ServerSocket class of java. Server.

Similar documents
Mobile Application Development Lab [] Simple Android Application for Native Calculator. To develop a Simple Android Application for Native Calculator.

CSE 660 Lab 3 Khoi Pham Thanh Ho April 19 th, 2015

M.A.D Assignment # 1

MAD ASSIGNMENT NO 3. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Basic GUI elements - exercises

COMP61242: Task /04/18

Software Practice 3 Before we start Today s lecture Today s Task Team organization

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Switching UIs

ANDROID PROGRAMS DAY 3

Fragment Example Create the following files and test the application on emulator or device.

Tabel mysql. Kode di PHP. Config.php. Service.php

Android Apps Development for Mobile and Tablet Device (Level I) Lesson 2

<uses-permission android:name="android.permission.internet"/>

Intents. Your first app assignment

Android UI Development

Mobile Software Development for Android - I397

IPN-ESCOM Application Development for Mobile Devices. Extraordinary. A Web service, invoking the SOAP protocol, in an Android application.

TextView Control. EditText Control. TextView Attributes. android:id - This is the ID which uniquely identifies the control.

Created By: Keith Acosta Instructor: Wei Zhong Courses: Senior Seminar Cryptography

ITU- FAO- DOA- TRCSL. Training on. Innovation & Application Development for E- Agriculture. Shared Preferences

Create Parent Activity and pass its information to Child Activity using Intents.

LifeStreet Media Android Publisher SDK Integration Guide

A Crash Course to Android Mobile Platform

MAD ASSIGNMENT NO 2. Submitted by: Rehan Asghar BSSE AUGUST 25, SUBMITTED TO: SIR WAQAS ASGHAR Superior CS&IT Dept.

Android Tutorial: Part 3

Data Persistence. Chapter 10

API Guide for Gesture Recognition Engine. Version 2.0

Manifest.xml. Activity.java

Arrays of Buttons. Inside Android

Android - JSON Parser Tutorial

Introduction to Android Development

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Saving State

EMBEDDED SYSTEMS PROGRAMMING Application Tip: Managing Screen Orientation

M.A.D ASSIGNMENT # 2 REHAN ASGHAR BSSE 15126

Android Programs Day 5

Android/Java Lightning Tutorial JULY 30, 2018

2.2 IoT Internet of Things Android Studio

Android App Development. Mr. Michaud ICE Programs Georgia Institute of Technology


Tip Calculator. xmlns:tools=" android:layout_width="match_parent"


Getting Started With Android Feature Flags

Android HelloWorld - Example. Tushar B. Kute,

Android Workshop: Model View Controller ( MVC):

Diving into Android. By Jeroen Tietema. Jeroen Tietema,

Multiple Activities. Many apps have multiple activities

Dynamically Create Admob Banner and Interstitial Ads

API Guide for Gesture Recognition Engine. Version 1.1

<uses-permission android:name="android.permission.internet" />

else if(rb2.ischecked()) {

PENGEMBANGAN APLIKASI PERANGKAT BERGERAK (MOBILE)

PROGRAMMING APPLICATIONS DECLARATIVE GUIS

Network Communication. 8.1 Introduction

LAMPIRAN. byte bcdtodec(byte val) { return( (val/16*10) + (val%16) ); } void setup() {

Learn about Android Content Providers and SQLite

Android Application Development. By : Shibaji Debnath

EMBEDDED SYSTEMS PROGRAMMING Application Basics

StoppUhr. <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="start1"

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Applied Cognitive Computing Fall 2016 Android Application + IBM Bluemix (Cloudant NoSQL DB)

Simple Currency Converter

Embedded Systems Programming - PA8001


EMBEDDED SYSTEMS PROGRAMMING Android Services

Android Beginners Workshop

Tutorial: Setup for Android Development

SMART VEHICLE TRACKING APPLICATION

Thread. A Thread is a concurrent unit of execution. The thread has its own call stack for methods being invoked, their arguments and local variables.

Starting Another Activity Preferences

COMP4521 EMBEDDED SYSTEMS SOFTWARE

Getting Started. Dr. Miguel A. Labrador Department of Computer Science & Engineering

Text Properties Data Validation Styles/Themes Material Design

Notification mechanism


android-espresso #androidespresso

android:orientation="horizontal" android:layout_margintop="30dp"> <Button android:text="button2"

EMBEDDED SYSTEMS PROGRAMMING UI Specification: Approaches

Software Practice 3 Today s lecture Today s Task

Adaptation of materials: dr Tomasz Xięski. Based on presentations made available by Victor Matos, Cleveland State University.

Vienos veiklos būsena. Theory

Produced by. Mobile Application Development. Higher Diploma in Science in Computer Science. Eamonn de Leastar

Our First Android Application

Android Services. Victor Matos Cleveland State University. Services

Object-Oriented Programming in Java

Interface ใน View class ประกอบด วย

Android Application Model I. CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr.

Android CardView Tutorial

INTRODUCTION TO ANDROID

Android Layout Types

ANDROID APPS DEVELOPMENT FOR MOBILE AND TABLET DEVICE (LEVEL I)

8/30/15 MOBILE COMPUTING. CSE 40814/60814 Fall How many of you. have implemented a command-line user interface?

Android Application Model I

10.1 Introduction. Higher Level Processing. Word Recogniton Model. Text Output. Voice Signals. Spoken Words. Syntax, Semantics, Pragmatics

An Overview of the Android Programming

Basic UI elements: Android Buttons (Basics) Marco Ronchetti Università degli Studi di Trento

Fragments. Lecture 11

APPENDIX CODE TO STORE THE BUTTON MENU AND MOVE THE PAGE

// MainActivity.java ; Noah Spenser; Senior Design; Diabetic Breathalyzer

EMBEDDED SYSTEMS PROGRAMMING Android NDK

Lecture 14. Android Application Development

Transcription:

CSE 660 Lab 7 Submitted by: Arumugam Thendramil Pavai 1)Simple Remote Calculator Server is created using ServerSocket class of java Server.java import java.io.ioexception; import java.net.serversocket; import java.net.socket; import java.util.scanner; import java.lang.*; import java.io.*; public class Server { public static void main(string[] args) { try{ ServerSocket serversocket = new ServerSocket(4444); System.out.println("Server Started..."); while(true){ new Thread(new ClientConnectionThread(serverSocket.accept())).start(); catch(ioexception e){e.printstacktrace(); class ClientConnectionThread implements Runnable{ private Socket socket; public ClientConnectionThread(Socket socket){ this.socket = socket; public void run(){ try{ DataInputStream din = new DataInputStream(socket.getInputStream()); DataOutputStream dout = new DataOutputStream(socket.getOutputStream()); String message = din.readutf(); System.out.println("Client Request : " + message); String[] input = message.split(" "); String result = input[0] + " " + input[2] + " " + input[1] + " = " + calculate(integer.parseint(input[0]),

Integer.parseInt(input[1]), input[2]); System.out.println("Server Response : " + result); dout.writeutf(result); dout.flush(); dout.close(); socket.close(); catch(ioexception e){e.printstacktrace(); public static String calculate(int num1, int num2, String operator) { Integer result = 0; switch (operator.charat(0)) { case '+': result = num1 + num2; case '-': result = num1 - num2; case '*': result = num1 * num2; case '/': result = num1 / num2; default: return Integer.toString(result); Android Client App : Changes were made to the AndroidManifest.xml file <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="example.calculator" > <uses-permission android:name="android.permission.internet" /> <uses-permission android:name="android.permission.access_network_state" /> <uses-permission android:name="android.permission.access_wifi_state" /> <uses-permission android:name="android.permission.change_wifi_state" /> <application android:allowbackup="true"

android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundicon="@mipmap/ic_launcher_round" android:supportsrtl="true" android:theme="@style/apptheme"> <activity android:name=".mainactivity"> <intent-filter> <action android:name="android.intent.action.main" /> <category android:name="android.intent.category.launcher" /> </intent-filter> </activity> </application> </manifest> MainActivity.java package example.calculator; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.textutils; import android.view.view; import android.widget.edittext; import android.widget.imageview; import android.widget.textview; import java.io.ioexception; import java.net.socket; import java.io.*; import java.net.unknownhostexception; import java.lang.*; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ EditText t1; EditText t2; MainActivity activity; ImageView plus; ImageView minus; ImageView multiply; ImageView divide; TextView displayresult; String oper = ""; Socket socket; String response = ""; /** Called when the activity is first created. */

public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // find the EditText elements (defined in res/layout/activity_main.xml t1 = (EditText) findviewbyid(r.id.t1); t2 = (EditText) findviewbyid(r.id.t2); plus = (ImageView) findviewbyid(r.id.plus); minus = (ImageView) findviewbyid(r.id.minus); multiply = (ImageView) findviewbyid(r.id.multiply); divide = (ImageView) findviewbyid(r.id.divide); displayresult = (TextView) findviewbyid(r.id.displayresult); // set listeners plus.setonclicklistener( this ); minus.setonclicklistener( this); multiply.setonclicklistener( this); divide.setonclicklistener( this); // public void onclick( View view ) { // check if the fields are empty if (TextUtils.isEmpty(t1.getText().toString()) TextUtils.isEmpty(t2.getText().toString())) { return; // perform operations // save operator in oper for later use switch ( view.getid() ) { case R.id.plus: oper = "+"; case R.id.minus: oper = "-"; case R.id.multiply: oper = "*"; case R.id.divide: oper = "/"; default:

new Thread(new Runnable() { public void run() { try { response = ""; socket = new Socket("10.0.2.2", 4444); DataOutputStream dout = new DataOutputStream(socket.getOutputStream()); DataInputStream din = new DataInputStream(socket.getInputStream()); dout.writeutf(t1.gettext() + " " + t2.gettext() + " " + oper); dout.flush(); response = din.readutf(); runonuithread(new Runnable() { public void run() { displayresult.settext(response); ); + e.tostring()); e.tostring()); din.close(); dout.close(); socket.close(); catch (UnknownHostException e) { e.printstacktrace(); displayresult.settext("unknownhostexception: " catch (IOException e) { e.printstacktrace(); displayresult.settext("ioexception: " + ).start(); UI - activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout

android:id="@+id/linearlayout1" android:layout_marginleft="12pt" android:layout_marginright="12pt" android:layout_margintop="4pt"> <EditText android:layout_marginright="6pt" android:id="@+id/t1" android:inputtype="number"> </EditText> <EditText android:layout_marginleft="6pt" android:id="@+id/t2" android:inputtype="number"> </EditText> </LinearLayout> <LinearLayout android:id="@+id/linearlayout2" android:layout_margintop="4pt" android:layout_marginleft="6pt" android:layout_marginright="6pt"> <ImageView android:src="@drawable/add" android:id="@+id/plus"> </ImageView> <ImageView android:src="@drawable/minus" android:id="@+id/minus"> </ImageView> </LinearLayout> <LinearLayout android:id="@+id/linearlayout3" android:layout_margintop="4pt" android:layout_marginleft="6pt" android:layout_marginright="6pt">

<ImageView android:src="@drawable/multiply" android:id="@+id/multiply"> </ImageView> <ImageView android:src="@drawable/divide" android:id="@+id/divide"> </ImageView> </LinearLayout> <TextView android:layout_marginleft="6pt" android:layout_marginright="6pt" android:textsize="12pt" android:layout_margintop="4pt" android:id="@+id/displayresult" android:gravity="center_horizontal"> </TextView> </LinearLayout> Output: Server execution Client :

Learning and Observation: Learned about Socket Connections. Learned about android communication via TCP. 2) Remote Random Number Generator RandomNumberServer.java import java.io.ioexception; import java.net.serversocket;

import java.net.socket; import java.util.scanner; import java.lang.*; import java.io.*; import java.util.random; import java.util.arrays; public class RandomNumberServer { public static void main(string[] args) { try{ ServerSocket serversocket = new ServerSocket(4444); System.out.println("Server Started..."); while(true){ new Thread(new ClientConnection(serverSocket.accept())).start(); catch(ioexception e){e.printstacktrace(); class ClientConnection implements Runnable{ private Socket socket; public ClientConnection(Socket socket){ this.socket = socket; public void run(){ try{ DataInputStream din = new DataInputStream(socket.getInputStream()); DataOutputStream dout = new DataOutputStream(socket.getOutputStream()); String message = din.readutf(); System.out.println("Client Request : " + message); String[] input = message.split(" "); String result = generaterandom(integer.parseint(input[0]), Integer.parseInt(input[1]), Integer.parseInt(input[2])); System.out.println("Server Response : " + result); dout.writeutf(result); dout.flush(); dout.close(); socket.close(); catch(ioexception e){e.printstacktrace(); public static String generaterandom(int num, int min, int max ) { int range = (max - min) + 1; String response =""; for(int i=0;i<num;i++) { response += Integer.toString((int)(Math.random() * range)

+ min) + " "; return response; Android Client UI - activity_main.xml <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:layout_height="match_parent" android:orientation="vertical"> <EditText android:id="@+id/edittext" android:layout_weight="0.99" android:ems="10" android:inputtype="textpersonname" android:text="enter Number" /> <EditText android:id="@+id/edittext2" android:ems="10" android:inputtype="textpersonname" android:text="lowerbound" /> <EditText android:id="@+id/edittext3" android:ems="10" android:inputtype="textpersonname"

android:text="upperbound" /> <Button android:id="@+id/button" android:layout_height="46dp" android:backgroundtint="@android:color/holo_blue_dark" android:text="submit" /> <TextView android:id="@+id/displayresult" </LinearLayout> </LinearLayout> android:layout_height="116dp" android:text="textview" /> MainActivity.java package example.randomnumberclient; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.text.textutils; import android.view.view; import android.widget.edittext; import android.widget.button; import android.widget.textview; import java.io.ioexception; import java.net.socket; import java.io.*; import java.net.unknownhostexception; import java.lang.*; public class MainActivity extends AppCompatActivity implements View.OnClickListener{ EditText n; EditText max; EditText min; TextView displayresult; Button submit; MainActivity activity;

Socket socket; String response = ""; /** Called when the activity is first created. */ public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); // find the EditText elements (defined in res/layout/activity_main.xml n = (EditText) findviewbyid(r.id.edittext); min = (EditText) findviewbyid(r.id.edittext2); max = (EditText) findviewbyid(r.id.edittext3); submit = (Button) findviewbyid(r.id.button); displayresult = (TextView) findviewbyid(r.id.displayresult); // set listeners submit.setonclicklistener(this); // public void onclick( View view ) { // check if the fields are empty if (TextUtils.isEmpty(n.getText().toString()) TextUtils.isEmpty(min.getText().toString()) TextUtils.isEmpty(max.getText().toString())) { return; new Thread(new Runnable() { public void run() { try { response = ""; socket = new Socket("10.0.2.2", 4455); DataOutputStream dout = new DataOutputStream(socket.getOutputStream()); DataInputStream din = new DataInputStream(socket.getInputStream()); dout.writeutf(n.gettext() + " " + min.gettext() + " " + max.gettext()); dout.flush(); response = din.readutf(); runonuithread(new Runnable() {

); public void run() { displayresult.settext(response); e.tostring()); e.tostring()); din.close(); dout.close(); socket.close(); catch (UnknownHostException e) { e.printstacktrace(); displayresult.settext("unknownhostexception: " + catch (IOException e) { e.printstacktrace(); displayresult.settext("ioexception: " + ).start();

I have successfully completed all parts of this assignment.