1
$\begingroup$

My basic idea of networking at the lowest layer is that one computer will send a bunch of parallel bits at a time down a cable and another computer will read these bits. For example, computer #1 sends a bunch of parallel bits to computer #2. Computer #2 then gets the bits then waits for the next bunch of bits. And so on.

I have a couple of questions about how this works and how we get around a few problems.

Problem #1: Say Computer #2 doesn't wait long enough for the next series of bits. Computer #2 may accidentally read the first set of bits twice, messing up communication.

Problem #2: Computer #2 waits too long. It doesn't read the second set of bits in time and only starts reading after the second set of bits are shown.

[to summarize problems 1 & 2, it seems like it would be very difficult to exactly sync the rate of transmition between the two computers)

Problem #3: We can't rely on every transmission to be different. So it's not like we can just wait for the transmission to change and then store the new value.

Problem #4: Say we use a special phrase. So after every transmission computer #1 signals to computer #2 that the transmission is going to change by flashing a bunch of 1's. This is a problem because what if our data is a bunch of 1s? We won't know if the transmission changed or not.

The only solution I can think of is to have some extra bit that alternates for each transmission, bit this seems like it wouldn't work for one-bit-at-a-time transmission networks like wifi. What part of all of this am I missing? How is this problem solved in the real world?

$\endgroup$
  • $\begingroup$ It seems this is about the electrical engineering part of networking, so might be off-topic here. $\endgroup$ – Yuval Filmus Sep 8 '17 at 5:34
2
$\begingroup$

On a wire you encode bits by changing the voltage, for example +5V could mean 1 and -5V could mean 0. If you do this naively you get problems with long sequences of 1's or 0's. For example you mentioned clock drift, i.e. when do I know that one 1 ended and the next 1 starts? But it's also problematic to have one voltage for a long time, because charge could build up at one end that needs to be dissipated somewhere.

So instead of using a naive encoding, we use a trick. For each bit we use two clock cycles, and encode the bit as the change in voltage. This way we implicitely also transmit our clock down the wire, the receiver can synchronise their clock using the same edge detection algorithm that they use to read the bits. This scheme is called Manchester code.

If you use more voltage levels to encode multiple bits at a time, the same basic idea can be applied. Instead of encoding the bits naively, we ensure that there is enough change in the data so that we can keep the clocks synchronised and the voltage on average 0. Check the related articles in the Wikipedia, for example 8b/10b encoding.

$\endgroup$
1
$\begingroup$

Adrian's answer covers your problems 1 and 2.

Problems 3 and 4 are solved by transmitting data in packets. Essentially, the transmitter divides the data they want to send into blocks and transmits the block one at a time. The blocks are typically of some fixed size and each block starts with (at the very least) the address of the recipient and how much actual data is in the block.

You also don't mention problem 5 which is "What happens if two computers are both transmitting at the same time?" This can happen even in a point-to-point network where only two computers use any particular wire, such as the cable between your computer and a router. In this case, anyone, including the transmitters, who's listening hears garbage – probably not even a signal that corresponds to any sequence of symbols – and both transmitters try again later. Obviously, in any sane protocol, a transmitter will first listen to see if the network is being used but it can still be that two transmitters decide to start simultaneously.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.