문제

In discussing push vs polling with a colleague, we were trying to figure out if there is a well-defined difference between two sides of a conversation being 'connected' vs being 'disconnected'. For an example, think of a TCP connection being 'open'.

We ended up deciding that the notion of 'being connected' is really just a question of degree. In other words, if communication seems relatively easy between the sides, then the phrases 'a connection is open' or 'the sides are currently connected' are used.

Is this view correct? Or is there some qualitative, well-defined difference between being two sides being connected vs disconnected?

도움이 되었습니까?

해결책

In networking, the technical term "connection" refers to a session where data is streamed (transmitted & received in-order). Sessions have a set-up and a tear-down phase where a channel (which can be virtual) is created & destroyed. TCP and ATM have connections, UDP doesn't.

If you're not using the technical term and wanted to include all types of network communications (e.g. UDP), you can still define "connected" concretely: two hosts are connected if they and intervening network devices have the necessary open data structures to send & receive messages to each other.

Here, "open" means the structures are in the correct states to send & receive messages to & from the other host. For example, consider the TCP state machine:

  • A TCP socket in a "LISTEN" state receives from any host on the network and can't send messages, so isn't part of a connection to another host.
  • Similarly, "CLOSED", "CLOSING", "TIME_WAIT" and "LAST_ACK" sockets can't send or receive* data, so aren't connected.
  • In opening states ("SYN_SENT" and "SYN_RCVD"), data can be sent along with a SYN packet, so you might be tempted to considered them "open". However, in practice data isn't sent with SYN packets and additional data can't be sent until the handshake completes. The latter especially means these states aren't "open".
  • Once a TCP socket enters the "ESTABLISHED" state, a connection exists.
  • With some of the closing states ("FIN_WAIT_1", "FIN_WAIT_2", "CLOSE_WAIT"), one side can only send, the other only receive. Thus, these opening and states shouldn't be considered to be fully "open".

That some data can be sent & received (with limitations) during opening and closing states suggests additional terms would be useful. In addition to "connected" and "not-connected", hosts can be "partially connected". During opening, the host has an "embryonic connection". The term "half-open" is often used for opening and closing states, though in a couple different ways: it can refer to half-duplex connections (such as TCP during closing), to connections where one host has closed without the knowledge of the other, and to embryonic connections.

Intervening network devices must be considered because devices on some network segments (e.g. the NAT on a home router, an ATM switch) may need to keep track of the connection to allow communication. If it's necessary but doesn't happen, the hosts won't be able to send or receive, so can't be said to be connected.

*: delayed, duplicate packets may still arrive during most of these states, but the packets are discarded and the application already received the data earlier, so (in a strict sense) the sockets aren't receiving data.

다른 팁

In basic networking you have end to end. That is what I would call connected. TCP is an end to end protocol. You get a delivery receipt. That is nice but there is overhead with an end to end communication.

You also have connectionless communication such as UDP or IP. You send it but do not get a delivery receipt.

A good book is Computer Networks and Internets by Douglas Comer. You can get it used quite cheaply. The fundamentals of networking have not changed much.

Poll versus push are typically both connected it is just which end initiates the connection. You don't typically send out a payload hoping it finds the destination.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top