1. Trang chủ
  2. » Công Nghệ Thông Tin

Lecture Computer networks 1: Lecture 8 - Phạm Trần Vũ

33 35 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 33
Dung lượng 1,75 MB

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

Nội dung

Lecture Computer networks 1 - Lecture 8: Transport layer and socket programming with Java has contents: Services provided to the upper layers, transport service primitives, berkeley sockets, an example of socket programming.

Trang 1

Computer Networks 1

(Mạng Máy Tính 1)

Lectured by: Dr Phạm Trần Vũ

Trang 2

Lecture 8: Transport Layer and Socket Programming with Java

Reference :

Chapter 6 - “Computer Networks”,

Andrew S Tanenbaum, 4th Edition, Prentice Hall, 2003.

Trang 3

The Transport Service

• Services Provided to the Upper Layers

• Transport Service Primitives

• Berkeley Sockets

• An Example of Socket Programming:

 An Internet File Server

Trang 4

Services Provided to the Upper

Layers

The network, transport, and application layers.

Trang 5

Transport Service Primitives

The primitives for a simple transport service.

Trang 6

Transport Service Primitives (2)

The nesting of TPDUs, packets, and frames.

Trang 7

Transport Service Primitives (3)

A state diagram for a simple connection management scheme

Transitions labeled in italics are caused by packet arrivals The

Trang 8

Berkeley Sockets

The socket primitives for TCP.

Trang 9

Elements of Transport Protocols

Trang 10

• Application addresses on a host: Ports

TSAPs, NSAPs and transport connections.

Trang 11

Connection Establishment

Three protocol scenarios for establishing a connection using a three-way handshake CR denotes CONNECTION REQUEST (a) Normal operation,

(b) Old CONNECTION REQUEST appearing out of nowhere (c) Duplicate CONNECTION REQUEST and duplicate ACK.

Trang 12

Connection Release

Abrupt disconnection with loss of data.

Trang 13

Connection Release (2)

The two-army problem.

Trang 14

Connection Release (3)

Four protocol scenarios for releasing a connection (a) Normal

case of a three-way handshake (b) final ACK lost.

Trang 15

The Internet Transport Protocols

 UDP – User Datagram Protocol

• Useful in client-server situations: Remote

Procedure Call, real-time AV streaming

 TCP – Transmission Control Protocol

network

Trang 16

UDP Header

Trang 17

TCP Service Model

connection end-points first, called sockets

address and a port number

 Port numbers < 1024 are reserved

Trang 18

Typical TCP Applications and Ports

69 TFTP Trivial File Transfer Protocol

79 Finger Lookup info about a user

110 POP-3 Remote e-mail access

Trang 19

The TCP Segment Header

Trang 20

TCP Connection Establishment

(a) TCP connection establishment in the normal case.

(b) Call collision.

Trang 21

Socket Programming in Java

Trang 22

Client-Server Application with UDP (1)

 Client operations

 Identify server IP and port

 Create UDP socket

 Send/receive data to server

 Close socket

 Create socket and register with the system

 Read client messages and respond to client

Trang 23

Client-Server Application with UDP (2)

Trang 24

Client-Server Application with TCP (1)

 Client operations

 Identify server IP and port

 Create UDP socket

 Setup connection to server

 Send/receive data

 Close connection

Trang 25

Client-Server Application with TCP (2)

 Create and register socket

 Listen and wait for incoming connections

 Accept connection

 Send/receive data

 Close connection

Trang 26

Client-Server Application with TCP (3)

 Concurrent server operations

 Create and register socket

 Listen and wait for incoming connections

 Accept connection and spawn new thread to handle the

Trang 27

Client-Server Application with TCP (4)

Trang 28

Java API: java.net package

Trang 29

InetAddress class

 Class used for internet addresses (Internet Protocol)

 Use methods: getLocalHost, getByName, or

getAllByName to create an InetAddress instance:

 public static InetAddess InetAddress.getByName(String

hostname)

 public static InetAddess [] InetAddress.getAllByName(String

hostname)

 public static InetAddess InetAddress.getLocalHost()

 To get the host IP address or host name:

 getHostAddress()

 getHostName()

Trang 30

Socket class (1)

 To describe a socket

 To create a socket

 Socket(InetAddress address, int port)

 Socket(String host, int port)

 Socket(InetAddress address, int port, InetAddress,

localAddr, int localPort)

 Socket(String host, int port, InetAddress, localAddr,

int localPort)

 Socket()

Trang 31

 public OutputStream getOutputStream() throws

IOException

 public InputStream getInputStream() throws

Trang 32

ServerSocket Class (1)

 Used for a server side socket

IOException

bindAddr) throws IOException

Trang 33

ServerSocket Class (2)

 int getLocalPort()

SocketException

Ngày đăng: 10/01/2020, 23:50