CS2105 3: Application Layer - 2

brandon·2023년 8월 29일
0

Network

목록 보기
3/13

1. Domain Name System

  • Servers communicate using ip addresses.

  • However, its easier for us to remember the host names instead.

  • This is why DNS server helps translating the host names to ip addresses.

  • Two ways to identify the host are:

    • Hostname : url
    • IP address : 32 bits segemented to 4 parts.
  • Domain Name System helps translating the host name into an ip address.

  • Sometimes the ip address can be multiple of them.

  • Canonical names are the official names of the host name.

    • Accessing through

DNS: Resource Records (RR)

  • type A: hostname to IP address
  • type NS: domain to hostname
  • type CNAME: alias name to domain (real, canonical) name
  • type MX: for mail server

Distributed, Hierarchical Database

  • Goes down each level.
  • Root Server:
  • Top Level Domains: .com, .org, .net, .edu, .sg, .uk, .jp...
  • Authoritative Server: Organization's own DNS server(s).

Local DNS Server

  • When host makes a DNS query, the query is sent to its local DNS server.

DNS Caching

  • Local DNS server caches the query (name-to-address) information in cache.
  • has expiracy date (Time To Leave (TTL)), in case ip addresses change, or other infos change.
  • DNS runs over UDP.
    • Packet loss does not happen usually, because the request is sent to local DNS server.
    • If it is lost, can query again.
    • Browser sends multiple DNS query back-to-back, in case one query is lost, other query can get in.
    • TCP is slower, because has to make a TCP connection first before the packets are sent.

DNS Name Resolution

  • The above is an iterative query.
  • local DNS server makes query to root, TLD, and authoritative DNS server, then stores the information.
  • Above is a recursive query.
  • iterative query is used more commonly than recursive query.

2. Socket Programming

Process

  • program running within a host.
  • Within the same host, two processes communicate using Inter-Process Communication (IPC).
  • Processes in different hosts communicate by exchanging messages.

Addressing Processes

  • IP address is 32-bit integer (e.g. 999.999.99.99)
  • IP address is not sufficient to identify a process running in a host.
  • IP address can identify a host, but does not know which process to pass the packets to, because there could be multiple processes.
  • A process is defined by (IP address and Port Number).
  • Port number is 16-bit integer.

Socket

  • Application interface between application processes and transport layer. (WHY?)
  • Could think of it as a set of APIs.

Socket Programming

  • TCP socket and UDP socket.

UDP Socket

  • Has no connection between the server and the client.
  • Client sends each packet that contains the IP addresses and port number of the destination.

UDP Socket Process

  • Datagram is a name of packet for UDP.

Example: UDP Socket Server

  • AF_INET is a specific version if IP address. Will be covered in future lectures.
  • Binding to '' means to bind to the localhost.
  • recvfrom() inside the paranthesis is the byte size of the buffer.

Example: UDP Socket Client

  • mesasge.encode() is to change string to bytes.

TCP Socket

  • TCP connection set when client creates a socket.
  • Server TCP creates a new socket for server process to communicate with the client.
    • This allows the server to communicate with multiple clients individually.

Example: TCP Server Socket

  • serverSocket.list() waits for the client to request for TCP connection.
  • accept() accepts the TCP connection, returning new socket to communicate with client socket.

Example: TCP Client Socket

  • connect() to send TCP connection request to the server socket.
  • Then is welcome socket necessary to create additional sockets for individual TCP connection requests?

TCP vs UDP Socket Programming

  • For UDP, we need to attach both IP address of the server and the port number for every request sent, because there is no persistent connection.
    • When a client application wants to send a UDP datagram, it always needs to specify the destination IP address of the server and the destination port number to the operating system's networking stack.
    • This is because each UDP datagram is an independent unit of data, and the OS needs to know where to send it. Since there's no pre-established connection, every single datagram needs its full addressing information to reach the intended recipient and application process.
  • For TCP however, we do not need to add the server name and port number because it uses persistent connection.
    • When a client application initiates a TCP connection (e.g., using connect() in a socket programming API), it provides the destination IP address of the server and the destination port number once to the operating system.
profile
everything happens for a reason

0개의 댓글