1. Trang chủ
  2. » Giáo Dục - Đào Tạo

INTERNET PROTOCOLS (lập TRÌNH MẠNG cơ bản SLIDE)

32 15 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 32
Dung lượng 539,5 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Uniform Resource Locator: URL Hierarchy of Classes  Methods of the Class  Examples of Using the Class... String getContentType; String getContentLength; long getLastModified;... Forma

Trang 1

INTERNET PROTOCOLS

Trang 3

Uniform Resource Locator: URL

 Hierarchy of Classes

 Methods of the Class

 Examples of Using the Class

Trang 4

Hierarchy of Classes

Trang 5

URL Class

 Class URL is a description of a resource location on the Internet

 Complete URL: http://www.cs.joensuu.fi:1547/~john/pub/index.html

Trang 6

Methods of URL Class

MalformedURLException).

Trang 7

Methods of URL Class

instantiated

An InputStream object is returned and permits to retrieve information specifed

into the URL

If the connection fails, the exception IOException is raised.

String getContentType();

String getContentLength();

long getLastModified();

Trang 8

Creating a URL Instance

 The following statement creates a Java URL object:

 You can also build a URL by setting each part individually:

URL u = new URL(“http”, www.cs.rpi.edu,80,”/~hollingd/”);

Trang 9

Retrieving Remote Files

Rather than reading the fle from the local system, this example reads the fle from a Web server

private void showFile() {

URL url = null;

Trang 10

Retrieving a Resource with the URL Class

import java.net.*;

import java.io.*;

public class FtpUrls {

public static void main(String[] args) throws IOException {

// URL url = new URL("ftp://pvtinh:Tinh7570@192.168.1.6/t.txt");

URL url = new URL("http://192.168.1.2/cackhoa.html");

InputStream uin = url.openStream();

BufferedReader in = new BufferedReader(new

Trang 11

SMTP

Trang 12

Format of an email

Trang 13

Commands and response

Trang 14

Command

Trang 15

Response

Trang 16

Response (con)

Trang 17

Status code

 The Server responds with a 3 digit code that may be followed by text info

 2## - Success

 3## - Command can be accepted with more information

 4## - Command was rejected, but error condition is temporary

 5## - Command rejected, Bad User!

Trang 18

Connection establishment

Trang 19

F Message transfer

Trang 20

FConnection termination

Trang 21

After connection, we can type the SMTP commands and then receive the responses as shown below We have shown the commands in black and the responses in color Note that we have added for clarification some comment lines, designated by the “=” sign These lines are not part of the email procedure.

Example

Trang 23

============= Connection Termination===============

250 Message received: adelphia.net@mail.adelphia.net

QUIT

221 mta13.adelphia.net SMTP server closing connection

Connection closed by foreign host.

Example

Trang 24

SMTP & Sending E-Mail

Trang 25

Simple Mail Transfer Protocol - RFC 821

 To send e-mail, you make a socket connection to port 25 , the SMTP port SMTP is the Simple Mail Transport Protocol that describes the format for e-mail messages.

 Open a socket to your host.

Socket s = new Socket("mail.yourserver.com", 25);

PrintWriter out = new PrintWriter(s.getOutputStream());

 Send the following information to the print stream:

HELO sending host # Domain name

MAIL FROM:< sender email address >

RCPT TO:< recipient email address >

Trang 26

Sending E-Mail

private BufferedReader in;

private PrintWriter out;

private JTextField from;

private JTextField to;

private JTextArea message;

……….

public void sendMail() {

try {

Socket s = new Socket(smtpServer.getText(), 25);

out = new PrintWriter(s.getOutputStream());

Trang 28

public void receive() throws IOException {

String line = in.readLine();

if (line != null) {

………

}

}

Trang 29

Limitations in SMTP

 Only uses NVT 7 bit ASCII format

 How to represent other data types?

 No authentication mechanisms

 Messages are sent un-encrypted

 Susceptible to misuse (Spamming,

faking sender address)

Trang 31

POP3

Trang 32

Receive E-Mail – POP3 (RFC 1939)

 // Login by sending USER and PASS commands

Ngày đăng: 29/03/2021, 10:50

TỪ KHÓA LIÊN QUAN

w