Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is TCP bidirectional or full-duplex?

Bidirectional and full-duplex are different concepts. For example the Ethernet is only half-duplex because at a specific time, only one host can send data over the wire, and it cannot send and receive data simultaneously.

So when we use TCP over an Ethernet, I think TCP is only bidirectional or half-duplex.

But here it says TCP is full-duplex. Why?

like image 521
smwikipedia Avatar asked Feb 13 '15 07:02

smwikipedia


People also ask

Is TCP full-duplex?

TCP is a transport-layer protocol that provides a reliable, full duplex, connection-oriented data transmission service. Most Internet applications use TCP.

Is TCP two way communication?

TCP is always 2-way. There is no 'send and forget' as with UDP. The first Program would have to open a Server Socket. This means, that it listens on port 25 for a TCP SYN (A flag, that signals that a connection is being opened).

What is half-duplex and full-duplex in TCP?

In simplex mode, Sender can send the data but that sender can't receive the data. In Half Duplex mode, Sender can send the data and also can receive the data but one at a time. In Full Duplex mode, Sender can send the data and also can receive the data simultaneously.

What type of communication is used in TCP half-duplex?

If Ethernet is run in half-duplex, then the node cannot transmit and receive at the same time. But this doesn't mean that the node cannot use TCP. TCP still runs on top of Ethernet, and additionally, on top of IP (Layer 3) to create the bidirectional connection that TCP needs to communicate.


5 Answers

It is both. It is bidirectional because it can send data in both directions, and it is full-duplex because it can do that simultaneously, without requiring line turnarounds, at the API level.

Of course at a lower level it may be restricted by the available physical layer.

like image 113
user207421 Avatar answered Nov 06 '22 21:11

user207421


It's certainly bidirectional, since both parties send / receive packets. What exactly do you mean when you ask if TCP is full-duplex?

Both sending and receiving packets at the same time has more to do with the physical component, while TCP is a protocol defining how data should be framed and handled in order to reach the destination.

The NIC (Network Interface Controller) is responsible for sending and receiving physical packets and you would have to check there about the half / full - duplex capabilities.

Wireless (802.11) for example is half-duplex if it is using the same antenna for sending and receiving radio signal.

like image 29
Razvan Avatar answered Nov 06 '22 22:11

Razvan


The TCP API is full-duplex. This mean that TCP API allow send data from both side of connection just in same time. Let's see the source of test program to proof:

#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>


void do_write(const char* who, int socket) {
    const char hello[] = "hello!";
    if( 0 < write(socket, hello, strlen(hello)) )
        printf( "%s: write done ok\n", who );
    else
        printf( "%s: write error: %s\n", who, strerror(errno) );
}

void do_read(const char* who, int socket) {
    /* do parental things with this end, like reading the child's message */
    char buf[1024];
    int n = read(socket, buf, sizeof(buf));
    if( 0 < n )
        printf("%s: received '%.*s' %db\n", who, n, buf, n);
    else if( 0 == n )
        printf( "%s: no data available\n", who );
    else
        printf( "%s: read error: %s\n", who, strerror(errno) );
}

int main() {
    int fd[2];
    static const int parent = 0;
    static const int child = 1;
    pid_t pid;

    socketpair(PF_LOCAL, SOCK_STREAM, 0, fd);

    pid = fork();
    if (pid == 0) {      /* child process */
        close(fd[parent]);
        do_write("child", fd[child]);
        do_read("child", fd[child]);
        /* sleep(1); */
        do_write("child", fd[child]);
        do_read("child", fd[child]);
    } else {             /* parent process */
        close(fd[child]);
        do_write("parent", fd[parent]);
        do_read("parent", fd[parent]);
        do_write("parent", fd[parent]);
        do_read("parent", fd[parent]);
    }

    return 0;
}

The output (on FreeBSD) is:

parent: write done ok
child: write done ok
child: received 'hello!' 6b
child: write done ok
parent: received 'hello!hello!' 12b
parent: write done ok
child: received 'hello!' 6b
parent: no data available

So TCP API is full-duplex and data may be sended from both side at the same time. I think that implementation is full-duplex too, but it need to write more complicated test to recognize. This is implementation dependent of course. And good implementation may does not effect when at least one transport chain link is not full-duplex.

like image 31
oklas Avatar answered Nov 06 '22 23:11

oklas


By reading the article you posted, I think it's clear that they're talking about TCP supporting full-duplex communication (emphasis mine):

[TCP] is a full duplex protocol, meaning that each TCP connection supports a pair of byte streams, one flowing in each direction.

like image 23
Agis Avatar answered Nov 06 '22 23:11

Agis


Yes, a TCP connection provides a full-duplex service. Let's understand the meaning of full-duplex. It means exchanging data(sending and receiving) between two entities at the same time. As TCP is a transport layer protocol and transport layer protocols provide logical communication between processes running on different hosts, here also the meaning of full duplex is in this respect.

Here full-duplex means "If there is a TCP connection between Process A on one host and Process B on another host, then application layer data can flow from Process A to Process B at the same time as application layer data flows from Process B to Process A". A TCP connection is also always point-to-point, that is, between a single sender and a single receiver. Remember, the data from Process A is yet to pass through layers below transport layer, similarly the data from Process B will pass through layers below transport layer.

Source: Computer Networking by Kurose, Ross.

like image 25
Abhishek Sharma Avatar answered Nov 06 '22 23:11

Abhishek Sharma