Android Introduction Hello Threads.

Slides:



Advertisements
Similar presentations
Android Application Development Tutorial. Topics Lecture 6 Overview Programming Tutorial 3: Sending/Receiving SMS Messages.
Advertisements

1 Android Introduction Hello Threads. 2 Goal Create an application that uses a background thread as a UDP server to receive messages from the UDP client.
Programming with Android: Network Operations
Socket UDP H. Fauconnier 1-1 M2-Internet Java. UDP H. Fauconnier M2-Internet Java 2.
SOCKET PROGRAMMING WITH MOBILE SOCKET CLIENT DEARTMENT OF COMPUTER SCIENCE IOWA STATE UNIVERSITY.
Multiplexing/Demux. CPSC Transport Layer 3-2 Multiplexing/demultiplexing application transport network link physical P1 application transport network.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Socket Programming TCP and UDP.
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public 1 Version 4.0 Network Services Networking for Home and Small Businesses – Chapter 6.
Voice Instant Messenger Andrew Miller CS 491B Fall 2006 Professor Sun.
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
1 Overview r Socket programming with TCP r Socket programming with UDP r Building a Web server.
STFTP (Simplified Trivial File Transfer Protocol) MODULE #1.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Datagram Programming A datagram is an independent, self-contained message sent over the network whose arrival, arrival time, and content are not guaranteed.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
19-Aug-15 About the Chat program. 2 Constraints You can't have two programs (or two copies of the same program) listen to the same port on the same machine.
Cosc 5/4730 A little on threads and Messages: Handler class.
CS4273: Distributed System Technologies and Programming I Lecture 5: Java Socket Programming.
Assignment 3 A Client/Server Application: Chatroom.
TCP/IP protocols Communication over Internet is mostly TCP/IP (Transmission Control Protocol over Internet Protocol) TCP/IP "stack" is software which allows.
DUE Hello World on the Android Platform.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Cli/Serv.: Chat/121 Client/Server Distributed Systems v Objectives –discuss a client/server based chat system –mention two other ways of chatting.
REVIEW On Friday we explored Client-Server Applications with Sockets. Servers must create a ServerSocket object on a specific Port #. They then can wait.
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
Threads and Services. Background Processes One of the key differences between Android and iPhone is the ability to run things in the background on Android.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
1 Chapter 28 Networking. 2 Objectives F To comprehend socket-based communication in Java (§28.2). F To understand client/server computing (§28.2). F To.
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Introduction to Socket Programming in Android Jules White Bradley Dept. of Electrical and Computer Engineering Virginia Tech
User Interface Android GUI Tool OpenGL API XML Writer Optimized Layout Algorithm WPF Component Inter.
@2010 Mihail L. Sichitiu1 Android Introduction Hello Threads.
Video Games list lab 6  At the end of this lab you will be expected to know:  What Views, View Groups, Layouts, and Widgets are and how they relate to.
By Vivek Dimri. Basic Concepts on Networking IP Address – Protocol – Ports – The Client/Server Paradigm – Sockets The Java Networking Package – The InetAddress.
1 Lecture 21 – April 4, 2002 Dynamic Loading Communication in Bond Message delivery Internal and external message format KQML Synchronous and asynchrounous.
1 Netprog 2002 TCP/IP UDP/IP in Java Based on Java Network Programming and Distributed Computing.
1 CSCD 330 Network Programming Fall 2013 Some Material in these slides from J.F Kurose and K.W. Ross All material copyright Lecture 8a Application.
A Local Area Network Chat Client ITTC LAN CHAT John Vincent Cecogo Jerikho Daguno Ardee Santos Elaine Mendoza Anjomar Pat Del Mindo Philip John Sales Philip.
Li Tak Sing COMPS311F. Case study: a multithreaded chat server The source contains 3 files: ChatServer //the chat server ChatThread //the thread on the.
1 Network Communications A Brief Introduction. 2 Network Communications.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Network Programming Communication between processes Many approaches:
Socket Programming Ameera Almasoud
Object-Orientated Analysis, Design and Programming
Concurrency in Android
Echo Networking COMP
Threads in Java Two ways to start a thread
Block 14 Group Communication (Multicast)
ITEC535 – Mobile Programming
PRESENTED To: Sir Abid………. PRESENTED BY: Insharah khan………. SUBJECT:
Network Programming Introduction
Hello Socket Programming TCP and UDP
Implementation CAN Communication Engine
Software Engineering for Internet Applications
Constructors, GUI’s(Using Swing) and ActionListner
Gurpreet Singh CSE/IT.
Threads, Handlers, and AsyncTasks
Socket Programming 2: Application Layer.
Chapter 5 & 6 UDP 서버/클라이언트 u-Network Design Lab 5.
CPSC 441 UDP Socket Programming
Chapter 2: Application layer
Multiplexing/Demux.
Server-Client communication without connection
Based on Java Network Programming and Distributed Computing
UI Elements 2.
Presentation transcript:

Android Introduction Hello Threads

Goal Create a basic chat application that uses broadcast UDP to send and receive messages on the local network (75%) Improve the chat application (25%) You: Your text

Layout ListView showing both the messages sent as well as received You: Your text ListView showing both the messages sent as well as received EditText allowing users to enter text to be sent Send button – sends the text

Application Structure ServerThread Main Activity Constructor Open the Socket If successful – “Server Started” Find the broadcast IP Address Find the IP Address OnCreate( ) Create the thread Start the thread run( ) while (socketStillOpen){ receive packet display Message send reply } Message Handler OnDestroy( ) close the socket sendPacket( ) send UDP OnClickListener( ) Send Message

Main Activity (HelloThreads) ClassMembers EditText msg; // For typing the message Button send; // For sending the message ListView msgList; // For displaying the message list ArrayAdapter <String>receivedMessages; // Holds the list of messages ServerThread myThread; // The server thread handling all networking Handler myHandler...... Similar to the one in HelloThreads OnCreate( ) Get handles (findViewById) to all GUI elements msgList = (ListView)findViewById(R.id.msgList); receivedMessages = new ArrayAdapter<String>(this, R.layout.message); msgList.setAdapter(receivedMessages); Create ServerThread: myThread=new ServerThread(getApplicationContext(),mHandler) Start the Thread: myThread.start(); Register the OnClickListener for the Send Button OnDestroy( ) OnClickListener( ) case PACKET_CAME: String incomingMessage = (String) msg.obj; receivedMessages.add("You: "+incomingMessage);

ServerThread public class ServerThread extends Thread Class Members Handler mHandler; // Handler for messages in the main thread Context mContext; // Context to the application (for getting ip Addresses) DatagramSocket serverSocket; // Socket used both for sending and receiving boolean socketOK=true; // True as long as we don't get socket errors InetAddress myBcastIPAddress; // my broadcast IP addresses InetAddress myIPAddress; // my IP addresses public ServerThread(Context currentContext,Handler handler){ mContext = currentContext; mHandler = handler; try serverSocket = new DatagramSocket(PORT); serverSocket.setBroadcast(true); ... catch and handle the exception try getMyWiFiBcastAndIPAddress(); ... catch and handle the exception run( ) – similar to HelloThreads, without the reply sendPacket(String msg) – similar to UDP sender in HelloSockets

Getting the IP Address: getMyWiFiBcastAndIPAddress( ); WifiManager mWifi = (WifiManager) (mContext.getSystemService(Context.WIFI_SERVICE)); WifiInfo info = mWifi.getConnectionInfo(); DhcpInfo dhcp = mWifi.getDhcpInfo(); int myIntegerIPAddress = dhcp.ipAddress; int myIntBroadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask; byte[] quads = new byte[4]; for (int k = 0; k < 4; k++) quads[k] = (byte) ((myIntegerIPAddress>> k * 8) & 0xFF); try{ InetAddress myIPAddress = InetAddress.getByAddress(quads); return myIPAddress; }catch(Exception e){ if(D) Log.e(TAG,"Cannot Get My Own IP Address"); return null }

Improvements Your choice of examples – below are only examples Different improvements are worth different amount of points Max points 125% Examples (only examples – go wild!): Add names to the messages Add images Add voice Add preferences Handle Application lifecycle (on restart, on pause, on resume, etc.) Vibrate or notify on receipt of a new message Handle landscape/portrait Localize it Looks (background, icon, button, etc.) Make utility for saving all messages in a file