Cosc 4755 Mobile networking Overview and Stream, Socket, and Datagram.

Slides:



Advertisements
Similar presentations
A Guide to Advanced Java Faculty:Nguyen Ngoc Tu. 2 Operating System Application #1 Application #2 Java Virtual Machine #1 Local Memory Shared Memory Threads.
Advertisements

Bruce Scharlau, University of Aberdeen, 2010 Java ME Networking Mobile Computing Some slides from MobEduNet This covers HTTP in detail, and mentions other.
Introduction to Sockets Jan Why do we need sockets? Provides an abstraction for interprocess communication.
III. Streams. Introduction Often a program needs to bring in information from an external source or to send out information to an external destination.
CS3505 The Internet and Info Hiway transport layer protocols : TCP/UDP.
Jan Java Networking UDP Yangjun Chen Dept. Business Computing University of Winnipeg.
Network Programming Chapter 11 Lecture 6. Networks.
Socket Programming.
A CHAT CLIENT-SERVER MODULE IN JAVA BY MAHTAB M HUSSAIN MAYANK MOHAN ISE 582 FALL 2003 PROJECT.
User Datagram Protocol. Introduction UDP is a connectionless transport protocol, i.e. it doesn't guarantee either packet delivery or that packets arrive.
Prepared By E. Musa Alyaman1 User Datagram Protocol (UDP) Chapter 5.
1 Java Networking – Part I CS , Spring 2008/9.
1 L53 Networking (2). 2 OBJECTIVES In this chapter you will learn:  To understand Java networking with URLs, sockets and datagrams.  To implement Java.
Cosc 5/4730 Blackberry: More of the GCF. Common Connections URL SchemeProtocolGCF TypeDefined by Btl2capBluetoothL2CAPConnectionJSR 82 datagramDatagramDatagramConnectionCLDC,
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
CSE/EE 461 Getting Started with Networking. Basic Concepts  A PROCESS is an executing program somewhere.  Eg, “./a.out”  A MESSAGE contains information.
Networking Support In Java Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Cosc 5/4730 Networking Overview and protocols. Basic networking Networking coding is based on a client and server model. – Even if the code you are writing.
1 Tutorial on Socket Programming Computer Networks - CSC 458 Department of Computer Science Yukun Zhu (Slides are mainly from Monia Ghobadi, and Amin Tootoonchian,
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
Web Proxy Server. Proxy Server Introduction Returns status and error messages. Handles http CGI requests. –For more information about CGI please refer.
Babak Esfandiari (based on slides by Qusay Mahmoud)
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.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
NET0183 Networks and Communications Lecture 31 The Socket API 8/25/20091 NET0183 Networks and Communications by Dr Andy Brooks Lecture powerpoints from.
Java Mobile Application sms,sim,mms and barcode application Presented by Ayedh(SIM and MMS) Asad(SMS and Barcode Application)
Windows Programming Using C# Internet Programming.
VIII. UDP Datagrams and Sockets. The User Datagram Protocol (UDP) is an alternative protocol for sending data over IP that is very quick, but not reliable:
DBI Representation and Management of Data on the Internet.
1 of 21 Atul Garg / Piyush Maheshwari / Aditya Kawatra DEVELOPMENT OF UNIVERSAL MEDIA PLAYER FACILITATOR — PROF. SUBRAT KAR (DEPT. OF ELECTRICAL ENGINEERING)
ICOM 6115©Manuel Rodriguez-Martinez ICOM 6115 – Computer Networks and the WWW Manuel Rodriguez-Martinez, Ph.D. Lecture 26.
UDP vs TCP UDP Low-level, connectionless No reliability guarantee TCP Connection-oriented Not as efficient as UDP.
Socket Programming in Java CS587x Lecture 4 Department of Computer Science Iowa State University.
Practicum: - Client-Server Computing in Java Fundamental Data Structures and Algorithms Margaret Reid-Miller 13 April 2004.
1 A TCP/IP Application Programming Perspective Chris Greenhalgh G53ACC.
Chapter 2 Applications and Layered Architectures Sockets.
Java Sockets Programming
L 2 - 1 3( 1/ 20) : Java Network Programming. The Socket API The previous contents describe client-server interaction that application programs use when.
Socket Programming Using JAVA Asma Shakil Semester 1, 2008/2009.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 15 IO Using http Rob Pooley
Cosc 5/4730 Networking Overview and protocols. Basic networking Networking coding is based on a client and server model. – Even if the code you are writing.
CS 158A1 1.4 Implementing Network Software Phenomenal success of the Internet: – Computer # connected doubled every year since 1981, now approaching 200.
Socket Programming Lab 1 1CS Computer Networks.
Part 4: Network Applications Client-server interaction, example applications.
PROG Mobile Java Application Development PROG Mobile Java Application Development Data Storage, Continued.
MIDP Programming Networking. Chapter Objectives The CLDC Streams Model Generic Connection Framework (GCF) Supported Protocols Creating a Connection Review.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
Prepared by Dr. Jiying Zhao University of Ottawa Canada.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Java Programming II Java Network (I) Java Programming II.
UDP User Datagram Protocol. About the UDP A commonly used transport protocol Does not guarantee either packet delivery or order The packets may travel.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
UDP Programming. Khoa CNTT – ĐH Nông Lâm TP. HCM 01/2007 2/86 Overview.
Generic Connection Framework Connection FileConnectionSocketConnectionHTTPConnection InputConnection OutputConnection StreamConnection.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
Network Programming. These days almost all devices.
Access to Remote Data ( ) Frank Ducrest.
The Java Platform Micro Edition Java ME
IO in java.
Object-Orientated Analysis, Design and Programming
Object Writing in files
MCA – 405 Elective –I (A) Java Programming & Technology
Network Programming Introduction
Networking.
NETWORK PROGRAMMING CNET 441
Process-to-Process Delivery: UDP, TCP
Exceptions and networking
Presentation transcript:

Cosc 4755 Mobile networking Overview and Stream, Socket, and Datagram.

A Overview Generic Connection Framework (GCF) – In Javax.microedition.io Now includes files, more network protocols, smart cards, RFID cards, bluetooth, and bar codes. – And is being ported back to Java SE as JSR 197

Some Connection Schemes URL SchemeProtocolGCF TypeDefined byRequired Btl2capBluetoothL2CAPConnectionJSR 82No datagramDatagramDatagramConnectionCLDC, CDC, JSR 197 No fileFile accessFileConnection, InputConnection JSR 75No httpHTTPHttpConnectionMIDP 1.0/2.0Yes httpsSecure HTTPHttpsConnectionMIDP 2.0yes comSerial I/OCommConnectionMIDP 2.0no sms, mmsSMS, MMSMessageConnectionJSR 120, JSR 205No apduApplication Protocol Data Unit (encryption and smart cards) APDUConnectionJSR 177no socket, serversocketSocketSocketConnection, ServerSocketConnection MIDP 2.0no datagramUDPUDPDatagramConnectionMIDP 2.0no

Implemented under profiles ConnectionRequired?CLCD 1.0, 1.1MIDP 1.0MIDP 2.0 CommConnectionNYes ConnectionYYes ContentConnectionYYes DatagramConnectionNyes HttpConnectionYyes HttpsConnectionYyes InputConnectionYyes OutputConnectionYyes SecureConnectionNYes ServerSocketConnectionNYes SocketConnectionNYes StreamConnectionYyes StreamConnectionNotifierYyes UDPDatagramConnectionNYes Normally implemented, but carrier or handset may not.

Common Connections Connector class is the abstracted view – Like when we used for file access. Connection interface, generic connection – defines the close method DatagramConnection interface, defines actions for a datagram connection, like UDP – Datagram interface, abstract interface for a datagram, which are bidirectional, extending the DataInput and DataOutput interfaces StreamConnection, defines actions on a stream connection, such as TCP – bidirectional, uses the InputConnection and OutputConnection ContentConnection interface, supports passes content encoded through a well-known codec – Video, audio, images.

Permission for Network Connection Network applications require privilege, which is imposed by the MIDLet. – This ensures that unauthorized network connection do not result in data use charges. – On a phone, may require sign app – At min, requires the JAD to specify the privileges they require, set in the JAD attributes MIDlet-Permissions – See Pg 327 in the book for more info. In the emulators, you app's runs as untrusted and connections are available if the user grants permission

URL syntax Where – scheme is the protocol (ie http, file, etc) – user is the username, which is optional – password is the password for the username, also optional – host is the fully qualified domain name or address – port is the optional port number, scheme provides the default – path is the path on the remote end the format varies by scheme. – Parameters are optional parameters, depends on scheme.

typical network code. String url = "socket:// … StreamConnection c = null; InputStream s = null; try { c = (StreamConnection)Connector.open(url); s = c.openInputStream(); int ch; while ((ch = s.read()) != -1) { //read every character until end of file (-1). } } catch (ConnectionNotFoundException e) { …} catch (IllegalArgumentException e) { …} catch (IOException e) { …} finally { if (s != null) s.close(); if (c != null) c.close(); }

StreamConnection Is the general method to open a network connection. – only provides openDataInputStream, openInputStream, openDataOutputStream, openOutputStream, and close methods. The following inherit StreamConnection – CommConnection, ContentConnection, HttpConnection, HttpsConnection, SecureConnection, SocketConnection

SocketConnection SocketConnection, provides us with the TCP connection (as does StreamConnection) – Provides methods some methods like we use in java SE and general UNIX socket programming. – String getAddress() Gets the remote address to which the socket is bound. – String getLocalAddress() Gets the local address to which the socket is bound. – int getLocalPort() Returns the local port to which this socket is bound. – int getPort() Returns the remote port to which this socket is bound. – int getSocketOption(byte option) Get a socket option for the connection. – void setSocketOption(byte option, int value) Set a socket option for the connection.

SocketConnection (2) Byte Option – DELAY: Socket option for the small buffer writing delay. – KEEPALIVE: Socket option for the keep alive feature. – LINGER: Socket option for the linger time to wait in seconds before closing a connection with pending data output. – RCVBUF: Socket option for the size of the receiving buffer. – SNDBUF: Socket option for the size of the sending buffer. Example s.setSocketOption(SocketConnection.DELAY,0); – basically like flush(), send small packets. int x = s.getSocketOption(SocketConnection.RCVBUF); – how big is the receive buffer?

Socket Example import javax.microedition.io.*; import java.io.*; String url = "socket://Somewhere.com:3012"; try { //connection should be it own method too. sock = (SocketConnection)Connector.open(url); in = new InputStreamReader(sock.openInputStream()); out = new OutputStreamWriter(sock.openOutputStream()); writeLine("Hi from a phone."); System.out.println("Wrote to System"); System.out.println("Now Waiting on input"); String from = getLine(); System.out.println("Server said:"+from); } catch (ConnectionNotFoundException e) { System.out.println("Something happened, ConnectionNotFoundException"); } catch (IllegalArgumentException e) { System.out.println("Something happened, IllegalArgumentException"); } catch (IOException e) { System.out.println("Something happened, IOExecption"); } finally { try { //close should be it's own method too. if (sock != null) sock.close(); if (in != null) in.close(); if (out != null) out.close(); } catch (IOException ex) { sock=null; in =null; out=null; } } And getLine and writeLine methods: public void writeLine(String to) { to +="\n"; if (out != null) { try { out.write(to.toCharArray(), 0, to.length()); } catch (IOException e) { label.setText("Failed to write"); } public String getLine() { // read from network port and have default value String from = ""; char ch; int i; if (in != null) { try { i = in.read(); while (i != -1 && (char) i != '\n') { from += (char) i; i = in.read(); } } catch (IOException e) { from = "AWGH!!!"; } return (from); }

Datagram and DatagramConnection Datagram and DatagramConnection are for UDP networking. – These work differently then Stream and Socket connection. – A datagramConnection, sends/receives a datagram. – There is no methods for OpenInputData and openOutputData streams. A datagramConnection can be a client or server

DatagramConnection like everything else, uses connector. – DatagramConnection dgc = null; Client – url = "data://somwhere.com:3012"; – dgc = (DatagramConnection)Connector.open(url); Server – url = "data://:3012"; //note no hostname! – dgc = (DatagramConnection)Connector.open(url);

datagram UDP is a connectionless protocol A datagram is the packet, which is sent or received. Datagram has – buffer, which is the data – offset, which is the pointer to current read or write – length, which is the size of the buffer. – header information is also available – There is also a reset method, to reuse the datagram.

datagram (2) The datagram uses the DataInput/Output methods readBoolean, writeBoolean readByte, WriteByte readChar, writeChar readFloat, writeFloat readShort, writeShore readInt, writeInt readLong, writeLong readUTF, writeUTF readFully, write – read/write an array of bytes.

datagram (3) Again, we can work with Strings instead. – Using the String functions to read/write bytes. – datagram has the two following methods (and the constructor) – byte[] = getData() //return the data buffer – setData(byte[] b, int offset, int length) //set buffer

UDP example import javax.microedition.io.*; import java.io.*; String url = "datagrame://somewhere.com:3012"; DatagramConnection dgc = null; Datagram d; String s = "Hello World"; byte m[] = s.getBytes(); String t; try { dgc = (DatagramConnection) Connector.open(url); //create the datagram with the data d = dgc.newDatagram(m,m.length); //send the datagram dgc.send(d); //now receive a datagram d.reset(); //reset for reuse dgc.receive(d); t = new String(d.getData()); System.out.println("Recieved: "+t); } catch (IOException ex) { …}

Server side. Sounds like an odd idea for a phone, but there are a number of reason – Mainly, what is called, "push" data sent to the phone. and other information – UDP uses the same as before, no host name and use receive method. – TCP, uses ServerSocketConnection method.

ServerSocketConnection Similar to a UNIX methods (java's too) Like UDP, no host is url line. url = "socket://:3012"; There is an acceptAndOpen() method – returns a SocketConnection useful methods – String getLocalAddress() – int getLocalPort()

ServerSocketConnection Example import javax.microedition.io.*; import java.io.*; private InputStreamReader in = null; private OutputStreamWriter out = null; private SocketConnection sock = null; private ServerSocketConnection ssc = null; String url="socket://:3012"; try { ssc = (ServerSocketConnection) Connector.open(url); System.out.println("localaddress is "+ssc.getLocalAddress()); sock = (SocketConnection)ssc.acceptAndOpen(); in = new InputStreamReader(sock.openInputStream()); out = new OutputStreamWriter(sock.openOutputStream()); //just like SocketConnection now //and close the sock, in, and out ssc.close(); } catch (IOException ex) { }

Server connections. This work until you close the application. – To have data pushed, use the MIDlet-push field in application descriptor. MIDlet-Push-1: socket://:3012, NameMIDlet,* – Now when data is received on port 3012, the server will be started up to respond to it. – Also can use the PushRegistery, part of the Wireless message API (WMA 1.1)

Q A &