OOP&M - laboratory lectures1 JPN – GUI and Applets “… I am sure ‘it wont fail as much as the one before …” - Bill Gates about W98 -

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 7 IO, Files, and URLs.
Advertisements

OOP&M - theory lectures1 OOP&M – the third day “… I cannot help with this terrible headache …” - Bjorn the morning after -
OOP&M - theory lectures1 OOP&M – the second day “… In the beginning God created the heavens and the earth …” - the Hollybook -
1 Creating a network app Write programs that  run on different end systems and  communicate over a network.  e.g., Web: Web server software communicates.
1 Java Networking – Part I CS , Spring 2008/9.
Programming Applets How do Applets work ? This is an HTML page This is the applet’s code It has a link to an applet.
Internet…issues Managing the Internet
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
OOP&M - laboratory lectures1 OOP&M – LAB2 LABzwei: the Input.
28-Jun-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
Java I/O – what does it include? Command line user interface –Initial arguments to main program –System.in and System.out GUI Hardware –Disk drives ->
Welcome to CIS 235 Computer Networks Fall, 2007 Prof Peterson.
15-Jul-15 Basic Protocols. 2 Sockets Sockets, or ports, are a very low level software construct that allows computers to talk to one another When you.
©Brooks/Cole, 2003 Chapter 6 Computer Networks. ©Brooks/Cole, 2003 Understand the rationale for the existence of networks. Distinguish between the three.
CEG3185 Tutorial 4 Prepared by Zhenxia Zhang Revised by Jiying Zhao (2015w)
TCP/IP Web Design & Layout January 23, TCP/IP For Dummies  The guts and the rules of the Internet and World Wide Web. A set of protocols, services,
INTRODUCTION TO WEB DATABASE PROGRAMMING
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
Lesson 24. Protocols and the OSI Model. Objectives At the end of this Presentation, you will be able to:
2: Application Layer1 Socket programming Socket API r introduced in BSD4.1 UNIX, 1981 r explicitly created, used, released by apps r client/server paradigm.
Chapter 16 The World Wide Web Chapter Goals Compare and contrast the Internet and the World Wide Web Describe general Web processing Describe several.
 TCP/IP is the communication protocol for the Internet  TCP/IP defines how electronic devices should be connected to the Internet, and how data should.
2013Dr. Ali Rodan 1 Handout 1 Fundamentals of the Internet.
1 ELEN602 Lecture 2 Review of Last Lecture Layering.
1 Computer Communication & Networks Lecture 28 Application Layer: HTTP & WWW p Waleed Ejaz
© 2007 Cisco Systems, Inc. All rights reserved.Cisco Public ITE PC v4.0 Chapter 1 1 Network Services Networking for Home and Small Businesses – Chapter.
Network Services Networking for Home & Small Business.
Jozef Goetz, Application Layer PART VI Jozef Goetz, Position of application layer The application layer enables the user, whether human.
1 CSC111H Client-Server: An Introduction Dennis Burford
Follow the Data Data (and information) move from place to place in computer systems and networks. As it moves it changes form frequently. This story describes.
RGEC MEERUT(IWT CS703) 1 Java Networking RGEC Meerut.
1 Streams Files are a computer’s long term memory Need ability for programs to –get information from files –copy information from program variables to.
CS61B L02 Using Objects (1)Garcia / Yelick Fall 2003 © UCB Kathy Yelick Handout for today: These lecture notes Computer Science 61B Lecture 2 – Using Objects.
Object Oriented Programming in Java Lecture 16. Networking in Java Concepts Technicalities in java.
Application Layer Khondaker Abdullah-Al-Mamun Lecturer, CSE Instructor, CNAP AUST.
CS 11 java track: lecture 6 This week: networking basics Sockets Vectors parsing strings.
Web Design & Development 1 Lec - 21 Umair Javed. Web Design & Development 2 Socket Programming.
Sockets Sockets A socket is an object that encapsulates a TCP/IP connection There is a socket on both ends of a connection, the client side and the server.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
1 cs205: engineering software university of virginia fall 2006 Network Programming* * Just enough to make you dangerous Bill Cheswick’s map of the Internet.
2: Application Layer1 Chapter 2: Application layer r 2.1 Principles of network applications r 2.2 Web and HTTP r 2.3 FTP r 2.4 Electronic Mail  SMTP,
TCP/IP (Transmission Control Protocol / Internet Protocol)
INTERNET PROTOCOLS. Microsoft’s Internet Information Server Home Page Figure IT2031 UNIT-3.
CSI 3125, Preliminaries, page 1 Java I/O. CSI 3125, Preliminaries, page 2 Java I/O Java I/O (Input and Output) is used to process the input and produce.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
TCP/IP Protocol Stack IP Device Drivers TCPUDP Application Sockets (Gate to network) TCP: –Establish connection –Maintain connection during the communication.
I/O Basics 26 January Aside from print( ) and println( ), none of the I/O methods have been used significantly. The reason is simple: most real.
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.
1 COMP 431 Internet Services & Protocols Client/Server Computing & Socket Programming Jasleen Kaur February 2, 2016.
Agenda Socket Programming The OSI reference Model The OSI protocol stack Sockets Ports Java classes for sockets Input stream and.
Data Communications and Computer Networks Chapter 2 CS 3830 Lecture 11 Omar Meqdadi Department of Computer Science and Software Engineering University.
SOCKET PROGRAMMING WITH JAVA By Collin Donaldson.
Advance Computer Programming Networking Basics – explores the java.net package which provides support for networking. – Also Called “programming for the.
Network Programming. These days almost all devices.
Chapter 11 Panko and Panko Business Data Networks and Security, 11 th Edition Copyright © 2016 Pearson Finally, Layer 5!
Prepared by: Dr. Abdallah Mohamed, AOU-KW Unit9: Internet programming 1.
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
Program Input/Output (I/O)
MCA – 405 Elective –I (A) Java Programming & Technology
Beyond HTTP Up to this point we have been dealing with software tools that run on browsers and communicate to a server that generates files that can be.
Vocabulary Prototype: A preliminary sketch of an idea or model for something new. It’s the original drawing from which something real might be built or.
I/O Basics.
Web Development & Design Chapter 1, Sections 4, 5 & 6
Topic 5: Communication and the Internet
I. Basic Network Concepts
Basic Protocols 24-Nov-18.
Basic Protocols 19-Feb-19.
Follow the Data Data (and information) move from place to place in computer systems and networks. As it moves it changes form frequently. This story.
Computer Networks Protocols
Presentation transcript:

OOP&M - laboratory lectures1 JPN – GUI and Applets “… I am sure ‘it wont fail as much as the one before …” - Bill Gates about W98 -

OOP&M - laboratory lectures2 JPN – Java and the Net Clients and Servers One of the reasons of the interest in Java is its delivery mechanism. Java applets do not reach the user as a fixed and closed product into a floppy or CD. Nor they are downloaded only once from the net to be used over and over again. Instead, they are embedded within a web page and downloaded anew with each loading of the web page. “Java applets are not only on the Internet, but are creatures of the net as well” - Arnow/Weiss -

OOP&M - laboratory lectures3 JPN – Java and the Net Internet Communication Communication on the internet can be defined as the transfer of data from one machine to another. Into this definition there are many different concepts that fit: - -Remote logins -Download of web pages and applets -Chat rooms -… Information is break into small pieces called packets and transferred in that form

OOP&M - laboratory lectures4 JPN – Java and the Net Internet Communication The machine that is sending the information is almost never connected directly to the receiver, so these packets are actually transferred from one machine to another through the internet until they arrive at their destination The machines responsible of this transfer of data are called routers and are dedicated only to this purpose. Therefore they use a special software and have special form (and are quite expensive … go to and check it out) The transfer of packets is not secure, they can get lost in the way. The connection between machines is not good enough, and the machines themselves have limited memory … if packets arrive at rate higher than machine’s process rate, they could be lost

OOP&M - laboratory lectures5 JPN – Java and the Net Internet Communication Network A Computer 1 Computer 2 Computer 3 Network B Computer 4 Computer 5 Computer 6 R2 R6 R4 R5 R1 R3 Computer 7 Computer 8Computer 9 Computer 10 Network C

OOP&M - laboratory lectures6 JPN – Java and the Net Internet Communication Network A Computer 1 Computer 2 Computer 3 Network B Computer 4 Computer 5 Computer 6 R2 R4 R5 R1 R3 Internet Communication is: –One way –Broken into packets –Unreliable (packets can get lost) –Transmitted over many hops

OOP&M - laboratory lectures7 JPN – Java and the Net Internet Communication Network A Computer 1 Computer 2 Computer 3 Network B Computer 4 Computer 5 Computer 6 R2 R4 R5 R1 R3 With TCP it appears to be: –Bidirectional –A continuous Stream –Reliable –Direct

OOP&M - laboratory lectures8 JPN – Java and the Net Internet Communication Every router must be connected, at least, to another router, so that there will always be a path of routers between any couple of machines residing in different networks. The fact of the looses in terms of packets makes the network a not useful tool for almost any kind of applications. But there is a set of tools, which are the communication protocols, in order to make possible, the use of the net a communication medium. First, the “Internet Protocol” is running in all the machines at the net. Our applications use the “Transfer Control Protocol”. Both observe how the packets are transferred through the network and forces the sender to repeat if any loose of data is detected. THIS EMULATES A DIRECT STREAM OF DATA BETWEEN TWO M.

OOP&M - laboratory lectures9 JPN – input / output to programs Java program keyboard monitor files network InputStream System.out FileOutputStream Java program FileInputStream System.in InputStream OutputStream

OOP&M - laboratory lectures10 JPN – input/output … an overview Java program InputStream bytes of data ewsc24rfds53Hej20Hur20m76ar20du20?rsf Input source We must build a bridge between the Java Program and the input source!!

OOP&M - laboratory lectures11 Stages JPN – input … as example Construct a reference to an InputStream object, and with it Construct an InputStreamReader object, and with it Construct a BufferedReader object This references could be of two types FileInputStreamReader for files BufferedInputStream for keyboard and the network Note that: InputStream inputs sequences of bytes into the program InputStreamReader models the stream of input as characters, but doesn’t recognize ends of line a.o. BufferedReader has got a collection of methods that allow us to work in a similar way as we did with PrintStream

OOP&M - laboratory lectures12 JPN – a board with keys, the example Java provides a predefined object to represent the stream of input that comes from the keyboard. System.in is a reference to this object contained into the BufferedInputStream class Unlike System.out, which refers to a PrintStream object and therefore can be used right away to write Strings to the monitor, System.in, a reference to a BufferedInputStream object, cannot be readily used to read Strings keyboard [existing] InputStream new InputStreamReader new BufferedReader keyb isr System.in

OOP&M - laboratory lectures13 the constructor for InputStreamReader accepts the keyboard (a BufferedInputStream reference) as its argument new InputStreamReader ( System.in ) Java provides System.in contained into the BufferedInputStream class the constructor for BufferedReader accepts a InputStreamReader reference as its argument new BufferedReader ( ISR ) JPN – a board with keys, the example

OOP&M - laboratory lectures14 The total declaration would be: InputStreamReader isr; BufferedReader keyb; isr = new InputStreamReader(System.in); keyb = new BufferedReader(isr); And now, for reading a line: InputStreamReader isr; BufferedReader keyb; String inputline; isr = new InputStreamReader(System.in); keyb = new BufferedReader(isr); inputline = keyb.readLine(); *.readLine() is a method from the BufferedReader class JPN – a board with keys, the example

OOP&M - laboratory lectures15 Example: a program that writes the “plural” of a word import java.io.*; /* * This program writes the plural of the word typed in the * keyboard … it just adds an “s” */ class plural { public static void main(String[] arg) throws Exception{ InputStreamReader isr; BufferedReader keyb; String inputline; isr = new InputStreamReader(System.in); keyb = new BufferedReader(isr); inputline = keyb.readLine(); System.out.print(inputline); System.out.println(“s”); } JPN – a board with keys, the example

OOP&M - laboratory lectures16 JPN – come IN PUT files Obtaining input from disk files is only a little bit more complicated than from the keyboard. Our starting point must be to find some sort of InputStream object. As we said before, both BufferedInputStream and FileInputStream belong to that class new FileInputStream new InputStreamReader new BufferedReader bsr isr System.in is already defined into the class BufferedInputStream, the problem is that the FileInputStream class does not have defined objects like that. Therefore we need to first define an object that makes reference to a file. fsr files

OOP&M - laboratory lectures17 JPN – come IN PUT files the constructor for InputStreamReader accepts a stream from a file (a FileInputStream reference) as its argument new InputStreamReader ( FileInputStream ) the constructor for FileInputStream accepts a file (a File reference) as its argument the constructor for BufferedReader accepts a InputStreamReader reference as its argument new BufferedReader ( ISR ) new FileInputStream ( file )

OOP&M - laboratory lectures18 JPN – come IN PUT files The total declaration would be: File f; FileInputStream fsr; InputStreamReader isr; BufferedReader bsr; f = new File(“Big_parties_many_potatis.txt”); fsr = new FileInputStream(f); isr = new InputStreamReader(fsr); bsr = new BufferedReader(isr);

OOP&M - laboratory lectures19 JPN – come IN PUT files Let’s read a couple of lines from the file and print them: File f; FileInputStream fsr; InputStreamReader isr; BufferedReader bsr; String inputline; f = new File(“Big_parties_many_potatis.txt”); fsr = new FileInputStream(f); isr = new InputStreamReader(fsr); bsr = new BufferedReader(isr); inputline = bsr.readLine(); System.out.println(inputline); inputline = bsr.readLine(); System.out.println(inputline);

OOP&M - laboratory lectures20 JPN – Streams from the internet When we are try to read information from the Web The Net as other communication media for our programs can be read using Streams There is a difference between what we saw until now and what will happen with the Net: files are in HTML code The constructors are: Strings; URL u; InputStream ins; InputStreamReader isr; BufferedReader link; u = new URL(" ins = u.openStream(); isr = new InputStreamReader(ins); link = new BufferedReader(isr); s = link.readLine(); As you see here, the structure is similar to the one that we saw for the files. The difference is at the constructor for the InputStream object, which is special!! But the method for reading the information is the same: *.readline()

OOP&M - laboratory lectures21 import java.net.*; import java.io.*; class MyFirstBrowser { public static void main(String[] arg) throws Exception { URL uNet; InputStream insNet; InputStreamReader isrNet; BufferedReader linkNet; String s; uNet = new URL(" insNet = uNet.openStream(); isrNet = new InputStreamReader(insNet); linkNet = new BufferedReader(isrNet); s = linkNet.readLine(); System.out.println(s); s = linkNet.readLine(); System.out.println(s); System.out.println("connection closed"); } Example – Just reading a file JPN – Streams from the internet

OOP&M - laboratory lectures22 Features needed: Interpret HTML TAGs underline a text if it is a link ( ) jump line with show the name of the images ( ) try to show tables (...) think how to ask to the user for the next jump to do... Interpret scripting languages JavaScript Visual Basic Script Perl Calls external applications Office Java Virtual Machine JPN – internet The Browser is much more than only that

OOP&M - laboratory lectures23 JPN – Java and the Net Sockets A TCP connection between two programs in many ways is like a phone connection. Data can move in both directions simultaneously. But, before the communication act takes place, the connection must be established  one party must call the other Both parties need something beside, like in a phone call, both speakers have a telephone. The analogy between the telephone and the programming world is the socket. It is to the communication between computers like the telephone between two persons In Java we model the telephone with an object of the Socket class. A socket is created for making a single TCP connection

OOP&M - laboratory lectures24 JPN – Java and the Net Sockets The arguments to the constructor of the socket are the machine to contact and the port where the communication will take place. The port could be understood as the extension to the phone number in a large phone system new Socket(“ 80); The socket provides the methods: *.getInputStream() and *.getOutputStream(), from whose return values BufferedReader objects and PrintStream objects can be constructed. These objects use the TCP connection as their input source or output target

OOP&M - laboratory lectures25 JPN – Java and the Net Sockets The typical example would look like: import java.io.*; import java.net.*; Socket s = new Socket(hostname, portnumber); BufferedReader br = new BufferedReader( new InputStreamReader( s.getInputStream())); PrintStream ps = new PrintStream( s.getOutputStream()); String line = br.readLine(); //reads from the host ps.println(“hej”); //writes to the host

OOP&M - laboratory lectures26 JPN – Java and the Net Client-Server Computing Sockets and TCP/IP connections allow programs to communicate throw the internet, but they don’t determine any particular style of communication or relationship between the programs. There is a widely used design approach for Internet applications - the so called client-server model – In this model, an application consist of one program running as server, and another as a client Server: a program that provides a service Client: a program that requests a service

OOP&M - laboratory lectures27 JPN – Java and the Net Client-Server Computing Client an server converse, what means that they follow some communication rules. From the point of view of the client, what happens is: 1.Creates a socket object with the machine address and port to the server 2.Sends a message to the server on the TCP connection associated to the socket 3.Waits for response from the server that will be: More information needed Requested action performed The requested data Each communication is established (1) only once, but the conversation can be repeated (2-3) many times

OOP&M - laboratory lectures28 JPN – Java and the Net Client-Server Protocols Each client-server application has its own rules (or protocol) governing the conversation between client and server The web clients and servers use one protocol called HyperText Transport Protocol (HTTP) clients and servers use a different protocol, called Simple Mail Transfer Protocol (SMTP) if we send mail or POP if we receive (there are other variants, like IMAP, a.o.)