1. Trang chủ
  2. » Giáo án - Bài giảng

Networking Programming

37 116 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 37
Dung lượng 401 KB

Nội dung

Networking programming 2 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Chapter’s Objectives 1. Connecting to a Server 2. Implementing Servers 3. Sending Email 4. URL Connection 5. Advanced Socket Programming 6. UDP 3 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Connecting to a Server  Using Telnet program.  Ex : telnet time-A.timefreq.bldrdoc.gov 13 4 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (1)  IP: Internet Protocol :  IP is a protocol for connecting networks  IP is a packet-based protocol  Packets can be dropped, garbled or re-ordered and duplicated:  IP promises nothing but best-effort delivery  IP usually runs over ethernet, but not always 5 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (2)  Addressing :  Every packet has a source and a destination  A Host is identified by an IP address.  IP addresses are 4 bytes  Example: 129.123.12.43  An IP can belong to only one host in the Internet  Routers use the IP addresses to decide where to direct packets 6 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (3)  TCP :  TCP is a stream-based protocol over IP  TCP promises a reliable transport  TCP takes care of packet ordering, packet loss and data corruption.  A TCP stream is a connection. 7 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (4) TCP over IP IP Header Src Dst IP Data TCP Header Type: TCP TCP Data Src Port Dst Port Seq Num Application Data 8 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (5)  TCP Connections :  A TCP connection is between a Client Host and a Server Host  The Server is passive; It just waits  The Client is active  More than one connection is allowed between to hosts  TCP connections are 4-tuples  {<src-host,src-port>,<dst-host,dst-port>} 9 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (6) Internet Reference Model Application Layer (HTTP, FTP, DNS, etc.) Transport Layer (TCP, UDP) Network Layer (IP) Link and Physical Layer 10 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Ports (1)  A computer usually has one physical connection to the network. So all the data from the the network comes through this connection.  If all the data comes through the same interface how does the computer redirect to specific applications?  Recall, with IP network addresses  The computer is identified by its 32-bit IP address  The port address is used to identify the specific program or application to send the packet to. [...]... Hải-Khoa CNTT- 20 Advanced Socket Programming( 1)  Socket Timeout :  The read methods will block until data is available    Socket s = new Socket( .); s.setSoTimeout(10000); // time out after 10 seconds In JDK1.4, we can uses direct as follow  Socket s=new Socket();  s.connect(new InetSocketAddress(host, port), timeout); Create by Võ Văn Hải-Khoa CNTT- 21 Advanced Socket Programming( 2)  Half-close... CNTT- 12 Implementing Servers (1) Socket:   The Java interface with a TCP connection is a socket  A socket is a Java object which has methods to connect, accept connections and transfer data  Core Networking is in java.net.*  TCP Sockets come in two flavours: ServerSocket and Socket Create by Võ Văn Hải-Khoa CNTT- 13 Implementing Servers (2)  java.net.Socket  Socket(InetAddress address, int port)... writer.flush(); socket.shutdownOutput(); // now socket is half closed // read response data String line; while ((line = reader.readLine()) != null) 23 Võ socket.close(); Văn Hải-Khoa CNTT- Advanced Socket Programming( 3)  java.net.InetAddress :  static InetAddress getByName(String name)  returns the address for “name” Throws UnknownHostException if it’s unknown  This class is the interface from Java . 12 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Port (3)  Somes well-know port 20 : FTP ( Data) 21 : FTP (Control) 23 : Telnet 80 : HTTP 139 : NETBIOS 13 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Implementing. 129.1 23. 12. 43  An IP can belong to only one host in the Internet  Routers use the IP addresses to decide where to direct packets 6 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM TCP/IP Overview (3)  TCP. Networking programming 2 Create by Võ Văn Hải-Khoa CNTT- ĐHCN Tp.HCM Chapter’s Objectives 1. Connecting to a Server 2. Implementing Servers 3. Sending Email 4. URL Connection 5.

Ngày đăng: 13/05/2014, 11:00

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN

w