An email program As a simple example of socket programming we can implement a program that sends email to a remote site As a simple example of socket.

Slides:



Advertisements
Similar presentations
Liang, Introduction to Java Programming, Fifth Edition, (c) 2005 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
Advertisements

Prepared By E. Musa Alyaman1 URLs, InetAddresses, and URLConnections Chapter 9.
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.
Chapter 24 Internet Networking. Chapter Goals To understand the concept of sockets To learn how to send and receive data through sockets To implement.
Network Programming CS3250. References Core Java, Vol. II, Chapter 3. Book examples are available from
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L24 (Chapter 25) Networking.
CIS – Spring Instructors: Geoffrey Fox, Bryan Carpenter Computational Science and.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L22 (Chapter 25) Networking.
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.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved Chapter 25 Networking.
13-Jul-15 Sockets and URLs. 2 Sockets A socket is a low-level software device for connecting two computers together Sockets can also be used to connect.
Implementing Application Protocols. Overview An application protocol facilitates communication between applications. For example, an client uses.
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.
PL-IV- Group A HTTP Request & Response Header
Networking java.net package, which provides support for networking. Its creators have called Java “programming for the Internet.” Socket :- A network socket.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
EE2E1. JAVA Programming Lecture 9 Network Programming.
Computer Networks  Network - A system of computers interconnected in order to share information.  Data transmission - consists of sending and receiving.
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
FTP (File Transfer Protocol) & Telnet
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Application Protocols: HTTP CSNB534 Semester 2, 2007/2008 Asma Shakil.
How Web Servers and the Internet Work by by: Marshall Brainby: Marshall Brain
An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket.
Internet Networking. Chapter Goals To understand the concept of sockets To learn how to send and receive data through sockets To implement network clients.
COMP 321 Week 7. Overview HTML and HTTP Basics Dynamic Web Content ServletsMVC Tomcat in Eclipse Demonstration Lab 7-1 Introduction.
CS4273: Distributed System Technologies and Programming I Lecture 7: Java Networking.
DBI Representation and Management of Data on the Internet.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
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.
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.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae, VUW Networking COMP # 22.
Networks Sockets and Streams. TCP/IP in action server ports …65535 lower port numbers ( ) are reserved port echo7 time13 ftp20 telnet23.
Topics Sending an Multipart message Storing images Getting confirmation Session tracking using PHP Graphics Input Validators Cookies.
TCP Sockets Reliable Communication. TCP As mentioned before, TCP sits on top of other layers (IP, hardware) and implements Reliability In-order delivery.
1 WWW. 2 World Wide Web Major application protocol used on the Internet Simple interface Two concepts –Point –Click.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
27.1 Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Internet Applications (Cont’d) Basic Internet Applications – World Wide Web (WWW) Browser Architecture Static Documents Dynamic Documents Active Documents.
UNIT-6. Basics of Networking TCP/IP Sockets Simple Client Server program Multiple clients Sending file from Server to Client Parallel search server.
Application of the Internet 1998/12/09 KEIO University, JAPAN Mikiyo
1 Lecture 9: Network programming. 2 Manipulating URLs URL is an acronym for Uniform Resource Locator and is a reference (an address) to a resource on.
1 Chapter 22 World Wide Web (HTTP) Chapter 22 World Wide Web (HTTP) Mi-Jung Choi Dept. of Computer Science and Engineering
Simple Web Services. Internet Basics The Internet is based on a communication protocol named TCP (Transmission Control Protocol) TCP allows programs running.
Working with URLs CSIE, National University of Tainan.
School of Engineering and Computer Science Victoria University of Wellington Copyright: Peter Andreae david streader, VUW Echo Networking COMP
Mail User Agent Submitted by: Geetha Chittireddy.
Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 33 Networking.
Echo Networking COMP
Instructor Materials Chapter 5 Providing Network Services
Networking CS 3470, Section 1 Sarah Diesburg
Web Development Web Servers.
Networking COMP
Computing with C# and the .NET Framework
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
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.
Java Network Programming
Lecture 9 Network Programming
14-мавзу. Cookie, сеанс, FTP и технологиялари
Chapter 23 – Internet Networking
Sockets and URLs 13-Nov-18.
URL in Java C343 Lab (Week 13).
Networking CS 3470, Section 1 Sarah Diesburg
Introduction to Client/Server Design
Chapter 27 WWW and HTTP Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Information Retrieval and Web Design
// Please Setting App_name to Send Successful
Presentation transcript:

An program As a simple example of socket programming we can implement a program that sends to a remote site As a simple example of socket programming we can implement a program that sends to a remote site  This is taken from Core Java, vol 2, chapter 3 servers use port number 25 which is the SMTP port servers use port number 25 which is the SMTP port  Simple mail transport protocol

A client socket to the mail server can be opened on port 25 A client socket to the mail server can be opened on port 25 SMPT uses the following protocol SMPT uses the following protocol Socket s=new Socket(“engmail.bham.ac.uk”,25); HELO sending host MAIL FROM:sender address RCPT TO: recipient address DATA mail message …. QUIT

The program uses a simple GUI to input the required information The program uses a simple GUI to input the required information The send button on the GUI calls the sendMail() method which outputs the correct protocol to the mail server The send button on the GUI calls the sendMail() method which outputs the correct protocol to the mail server Socket s=new Socket(“engmail.bham.ac.uk”,25); out=new PrintWriter(s.getOutputStream()); String hostname=InetAddress.getLocalHost().getHostName(); out.println(“HELO “ + hostname); out.println(“MAIL FROM: “ + from.getText()); etc

URL connections We have seen that to send or retrieve information to a web server, we use the HTTP protocol through a client socket attached to port 80 We have seen that to send or retrieve information to a web server, we use the HTTP protocol through a client socket attached to port 80 We can do this by using normal socket-based programming and sending the correct HTTP commands We can do this by using normal socket-based programming and sending the correct HTTP commands However, Java has specific support for the HTTP protocol through its URLConnection class However, Java has specific support for the HTTP protocol through its URLConnection class  Its very easy to retrieve a file from a web server by simply providing the file’s url as a string

This sets up an input stream from a url connection This sets up an input stream from a url connection  Can turn this into a Scanner object for text processing The URLConnection class also has additional functionality related to the HTTP protocol The URLConnection class also has additional functionality related to the HTTP protocol  Querying the server for header information  Setting request properties URL u=new URL(“ URLConnection c=u.openConnection(); InputStream in=c.getInputStream();

The following simple example program opens a web page and displays the HTML The following simple example program opens a web page and displays the HTML It also checks the server response code It also checks the server response code  404 if the page is not found  200 if the connection succeeded Uses a Scanner object to output the lines of HTML Uses a Scanner object to output the lines of HTML

public class URLGet { public static void main(String[] args) throws IOException { String urlName; if (args.length > 0) urlName = args[0]; else urlName = " URL url = new URL(urlName); URLConnection c = url.openConnection(); // Check response code HttpURLConnection httpConnection = (HttpURLConnection) c; int code =httpConnection.getResponseCode(); String message=httpConnection.getResponseMessage(); System.out.println(code + " " + message); if (code!=HttpURLConnection.HTTP_OK) return; // Read server response InputStream instream=connection.getInputStream(); Scanner in=new Scanner(instream); while (in.hasNextLine()) { String input=in.nextLine(); System.out.println(input); }