@2010 Mihail L. Sichitiu1 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.
Socket Programming ENTERPRISE JAVA. 2 Content  Sockets  Streams  Threads  Readings.
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.
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L23 (Chapter 25) Networking.
STFTP (Simplified Trivial File Transfer Protocol) MODULE #1.
Cosc 4755 Phone programming: GUI Concepts & Threads.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
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.
By: Joel Rodriguez.  International student from Mexico  Delicias, Chihuahua Mexico  Spanish  Sports and Music.
CS 352-Socket Programming & Threads Dept. of Computer Science Rutgers University (Thanks,this slides taken from er06/
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.
16 Services and Broadcast Receivers CSNB544 Mobile Application Development Thanks to Utexas Austin.
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.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
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.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
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.
User Interface Android GUI Tool OpenGL API XML Writer Optimized Layout Algorithm WPF Component Inter.
Mobile Programming Midterm Review
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.
1 Project 3 The Kumquat Society Conference. 2 Conference Registration In this project you will write a program to handle a conference registration. The.
SEALANDINGS 2016 Groundfish landings. CREATE A GROUNDFISH LANDING REPORT  Go to File > New  Select Groundfish Landing if you want to create a landing.
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.
MT311 Java Application Development and Programming Languages Li Tak Sing ( 李德成 )
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.
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:
Block 14 Group Communication (Multicast)
ITEC535 – Mobile Programming
Network Programming Introduction
Hello Socket Programming TCP and UDP
Android Introduction Hello Threads.
Software Engineering for Internet Applications
Constructors, GUI’s(Using Swing) and ActionListner
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.
Based on Java Network Programming and Distributed Computing
Presentation transcript:

@2010 Mihail L. Sichitiu1 Android Introduction Hello Threads

@2010 Mihail L. Sichitiu2 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

@2010 Mihail L. Sichitiu3 Layout ListView showing both the messages sent as well as received EditText allowing users to enter text to be sent Send button – sends the text

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

@2010 Mihail L. Sichitiu5 Main Activity (HelloThreads)  ClassMembers EditTextmsg; // For typing the message Button send; // For sending the message ListViewmsgList; // For displaying the message list ArrayAdapter receivedMessages; // Holds the list of messages ServerThread myThread; // The server thread handling all networking HandlermyHandler Similar to the one in HelloThreads  OnCreate( ) Get handles (findViewById) to all GUI elements msgList = (ListView)findViewById(R.id.msgList); receivedMessages = new ArrayAdapter (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 );

@2010 Mihail L. Sichitiu6 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

@2010 Mihail L. Sichitiu7 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 Mihail L. Sichitiu8