4-Connection Management

Please indicate the source: http://blog.csdn.net/gaoxiangnumber1Welcome to my github: https://github.com/gaoxiangnumber14.1 TCP ConnectionsA client application can open a TCP/IP connection to a server
摘要由CSDN通过智能技术生成

Please indicate the source: http://blog.csdn.net/gaoxiangnumber1

Welcome to my github: https://github.com/gaoxiangnumber1

4.1 TCP Connections

  • A client application can open a TCP/IP connection to a server application. Once the connection is established, messages exchanged between the client’s and server’s computers will never be lost, damaged, or received out of order.
  • Though messages won’t be lost or corrupted, communication between client and server can be severed if a computer or network breaks. In this case, the client and server are notified of the communication breakdown.

  • Given URL “http://www.joes-hardware.com:80/power-tools.html”, your browser performs the steps shown in Figure 4-1.
    In Steps 1-3, the IP address and port number of the server are pulled from the URL. A TCP connection is made to the web server in Step 4 and a request message is sent across the connection in Step 5. The response is read in Step 6, and the connection is closed in Step 7.

4.1.1 TCP Reliable Data Pipes

  • TCP gives HTTP a reliable bit pipe. Bytes stuffed in one side of a TCP connection come out the other side correctly, and in the right order(Figure 4-2).

4.1.2 TCP Streams Are Segmented and Shipped by IP Packets

  • TCP sends its data in IP datagrams. A secure variant, HTTPS, inserts a cryptographic encryption layer(TLS or SSL) between HTTP and TCP(Figure 4-3b).

  • When HTTP wants to transmit a message, it streams the contents of the message data through an open TCP connection. TCP takes the stream of data, chops up the data stream into segments, and transports the segments across the Internet inside IP packets(Figure 4-4).

  • Each TCP segment is carried by an IP packet from one IP address to another IP address. Each of these IP packets contains:
    1. An IP packet header(usually 20 bytes)
    2. A TCP segment header(usually 20 bytes)
    3. A chunk of TCP data(0 or more bytes)

4.1.3 Keeping TCP Connections Straight

  • A TCP connection is distinguished by four values:

4.1.4 Programming with TCP Sockets

  • Table 4-2 shows some interfaces provided by the sockets API. This sockets API hides the details of TCP and IP from the HTTP programmer.
  • The pseudocode in Figure 4-6 sketches how we use the sockets API to highlight the steps the client and server could perform to implement Fig.4-1.

4.2 TCP Performance Considerations

4.2.1 HTTP Transaction Delays

  • Figure 4-7. The transaction processing time can be small compared to the time required to set up TCP connections and transfer the request and response messages. Unless the client or server is overloaded or executing complex dynamic resources, most HTTP delays are caused by TCP network delays.
  • Possible causes of delay in an HTTP transaction:
    1. A client first needs to determine the IP address and port number of the web server from the URI. If the hostname in the URI was not recently visited, it may take tens of seconds to convert the hostname from a URI into an IP address using the DNS resolution infrastructure.
      Most HTTP clients keep DNS cache of IP addresses for recently accessed sites. When the IP address is cached, the lookup is instantaneous. Because most web browsing is to a small number of popular sites, hostnames usually are resolved very quickly.
    2. Next, the client sends a TCP connection request to the server and waits for the server to send back a connection acceptance reply. Connection setup delay occurs for every new TCP connection. This usually takes at most a second or two, but it can add up quickly when hundreds of HTTP transactions are made.
    3. Once the connection is established, the client sends the HTTP request over the newly established TCP pipe. The web server reads the request message from the TCP connection as the data arrives and processes the request. It takes time for the request message to travel over the Internet and get processed by the server.
    4. The web server then writes back the HTTP response, which also takes time.
  • The magnitude of these TCP network delays depends on hardware speed, the load of the network and server, the size of the request and response messages, and the distance between client and server.

4.2.2 Performance Focus Areas

4.2.3 TCP Connection Handshake Delays

  • When you set up a new TCP connection, before you send any data, the TCP software exchanges a series of IP packets to negotiate the terms of the connection(Figure 4-8). These exchanges can significantly degrade HTTP performance if the connections are used for small data transfers.

  • Steps in the TCP connection handshake:
    1. To request a new TCP connection, the client sends a small TCP packet(usually 40-60 bytes) that has a “SYN” flag set to th
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值