Can TCP transmit multiple application layer messages concurrently withing the same TCP connection? - tcp

I’m reading the article how TCP breaks application message into smaller parts (TCP segments) and use sequence and acknowledge numbers for interacting. In the article there is a example how is transmitting one application layer message within one TCP connection. So, I have a question. Can TCP transmit multiple application layer messages concurrently withing the same TCP connection.
In other words:
Creating TCP connection between client and server.
Client breaks message1 from application layer into TCP segments and start sending them
Client breaks message2 from application layer into TCP segments and start sending them
Client breaks message3 from application layer into TCP segments and start sending them
Step 2,3,4 are going in parallel withing the same TCP connection.
Server receives segments from message1, message2, message3 and send responses in parallel.
Is this possible somehow in TCP? Or we can transmit messages only consequently within the same TCP connection. I’m interested in TCP protocol itself, it doesn’t matter what tricks are used in application layer like multiplexing.

I’m reading the article how TCP breaks application message into smaller parts
TCP does not break application messages into smaller parts because there is no concept of an "application message" at the TCP level. From the perspective of TCP there is only a byte stream with no inherent semantics. Arbitrary splitting but also merging can be done at the byte stream for optimal transport. All what matters is that the bytes are delivered reliably, in order and without duplicates to the peer.
Any application which relies on TCP somehow maintaining message boundaries is broken - and StackOverflow is full of such examples and the problems caused by this.
Can TCP transmit multiple application layer messages concurrently withing the same TCP connection.
It is up to the application protocol and not TCP to implement such a behavior. For example HTTP/1 has only a concept of one message after the other - which clear protocol defined boundaries where messages start and end in the byte stream. In HTTP/2 messages can overlap though because HTTP/2 implements some kind of multiplexing inside the application protocol. But again - all of this is defined and implemented at the application layer and not at the transport layer (TCP).

Related

TCP/IP ACK sender: Transport layer or the app?

A newbie question: who exact send the ACK, the transport layer or the app? I have a COM-server with particle counters to send the data to my app. Sometimes I have a lost data. When I check the Wireshark protocol I see that the packets were sent from COM-Server but failed ACK from receiver. I think that ACK is missing because the my program has the error and can't edit the data properly. My colleague says that the interface (socket) simply gets no data and can't return ACK. Who is right?
TCP is a transport layer protocol. The ACK is part of TCP. Thus the ACK is part of the transport layer and send there.
Note that there might be apps which include the transport layer (i.e user space TCP implementations) in which case the ACK is send by the app, but not in the application layer but still in the transport layer. But in most cases TCP is implemented in the kernel and is thus outside the app. See OSI or TCP/IP model for more information about these layers.
My colleague says that the interface (socket) simply gets no data and can't return ACK. Who is right?
Assuming that you are not using a user space TCP implementation: The OS kernel will ACK the data as soon as these data are put into the socket buffer of your application. It will not ACK the packet if it failed to put it into the socket buffer, i.e. if the socket buffer is full because your application failed to read the data. In this case it will also reduce the window so that the peer will not send anymore data.

When exactly are network packets created?

At which point in message transmission from client to host (or vice versa) is the message actually sliced into packets?
From my current understanding, the application puts an entire file in the socket and hands it over to TCP entirely. TCP first buffers the file/message, and when the time is right (when is the time right?) cuts chunks of the buffer data (creates packets) and adds TCP headers to transform chunks into segments.
Why do we talk about packets in the application layer, if there are no packets in the application layer at all? Just whole files... This doesn't add right.
Can someone confirm my understanding?
A TCP-based application has a message to send. What the message is depends on the application — it could be just a small request, or a whole file. It passes the message to the transport layer (TCP), which chops up the message into segments and passes them one by one to the network layer (Internet Protocol). The network layer adds a header to each packet, and passes it to the link layer (Ethernet), which handles frames.
So, in principle, we have:
messages at the application layer;
segments at the transport layer;
packets at the network layer; and
frames at the link layer.
In practice, however, people are not that pedantic, and tend to mix the notions up. You'll often hear people speak about TCP packets (the correct term would be IP packets with a TCP payload), and they will even speak about the application sending packets (the correct formulation would be that the application passes messages to the transport layer). Most of the time the inexact terminology is not a problem, since context disambiguates things.
The data are sliced into, and encapsulated by segments at the transport layer (UDP, TCP). The segments are encapsulated by packets by the network layer (IPv4, IPv6, etc.). The packets are encapsulated by frames at the data-link layer (ethernet, etc.).

TCP vs UDP - What is a TCP connection? [duplicate]

This question already has answers here:
Difference between TCP and UDP?
(13 answers)
Closed 4 years ago.
What exactly is a TCP connection?
I understand there isn't a physical connection from the client to server. Is this connection just the client's socket being linked with the new socket created by the server after the three-way-handshake?
Thereafter once the "connection" is set up, the sockets on either ends of the connection then know where to send their packets.
How does this differ from the way UDP functions other than the initial handshake with TCP?
Is it that each server socket only has one client that sends packets to that particular socket?
What are some possible advantages of having a dedicated connection between hosts? My understanding of TCP and UDP is still very basic, so broad generalizations should suffice.
Let's break this up into parts. First of, the network is based in IP, which is a protocol that assigns an address to each network node, and which allows you to send small amounts of data (usually up to 64kB, but typically only 1500B) from one node to another.
That by itself isn't worth much yet, because we can't make any checks that the data actually arrived, and that it arrived in the right order. If we want an abstract mechanism to transmit arbitrary amounts of data and ensure that they arrived, we need another protocol on top of the network that handles this "transmission". And that's the purpose of TCP.
However, in parallel to TCP, there's another "transmission" protocol that doesn't do any checking at all and has no reliability, UDP. UDP is just a thin wrapper around raw IP packets, which adds a little bit of meta data (like a port number).
UDP is still useful, though, since there are many situations in which the data integrity is already handed off to an even higher protocol, so there's no need for a complex transmission protocol. This is for example used in virtual networking services, where another instance of TCP/IP is typically run over a UDP channel. (Making the channel use a reliable protocol like TCP can actually have disastrous consequences in that case due to resend cascades.)
So the term "TCP connection" refers to the application of the TCProtocol. The protocol is stateful, naturally, and typically proceeds in a SYN-ACK-data-FIN sequence, or SYN/RST in case of a rejected transmission; both peers maintain a status of the connection (handshake, established, closing, closed.) TCP also introduces the terms "server" and "client", the server being the peer that listen()s for an incoming connection.
The main difference between TCP and UDP sockets is that UDP is conectionless and doesn't use any confirmation that the other end received the data.
The Transmission Control Protocol (TCP) is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol (IP), and therefore the entire suite is commonly referred to as TCP/IP. TCP provides reliable, ordered delivery of a stream of bytes from a program on one computer to another program on another computer. TCP is the protocol that major Internet applications such as the World Wide Web, email, remote administration and file transfer rely on. Other applications, which do not require reliable data stream service, may use the User Datagram Protocol (UDP), which provides a datagram service that emphasizes reduced latency over reliability.1

What is the difference between UDP and TCP packets? What do you use them for?

I was configuring IPtable yesterday. My colleague just asked me this question, and I couldn't anwser. I realized that I'm a much better developper than sysadmin and need to improve that.
So what are they? What are they for? Cons/Pros (if it's relevant).
These are like basic questions.
UDP :: User Datagram Protocol
1) No end to end Connection between to machines (may be in local network or somewhere in the internet).
2) The data received at the receiver end is not in stream as in TCP but as a complete block of data.
3) At the transport layer no packet order check is performed. That is in case of any error in the received packet, the receiver will not ask for resending the same packet to the sender.
4) Because of the above behaviour no sending buffers are required at the sender's end.
5) As no end to end connection is estld. and there are no handshakings required, UDP are pretty much faster but less reliable than TCP. Thus mostly used in gaming and DNS etc..
6) No acknowledgement required to be sent after recieiving packets.
TCP :: Transmission control Protocol
1) End to end Connection is maintained between to machines (may be in local network or somewhere in the internet).
2) The data received at the receiver end is a stream in TCP. Thus, when we do network programming for servers we first parse the header first and then depending upon the size mentioned in the header we obtain that much more number of bytes from the buffer.
3) Error checking and sequence number are all done. Thus in case any packet is received out of order (rarely) or is erred than that packet is made to resend. Also, lots of other protocols are involved for flow control (end to end flow control).
4) As connection establishment , handshaking and acknowledgement is to be done TCP are basically slower in operation than UDP.(Not significantly I believe)
5) Lots of protocols uses TCP as underlying transport protocol. HTTP,FTP,TELNET etc..
6) The communication procedure involves:
Server:: 1) Socket Open
2) Socket Bind
3) Socket Listen
4) Socket Accept
5) Socket Send/Recv
Client :: 1) Socket Open
2) Socket Connect
3) Socket Send/Recv
There are lots of other differeces also..but the above being the most common ones.
TCP is a reliable protocol which ensures that your packets reach their destination and is used in applications where all data must me trasfered accurately between parties. TCP requires both parties to negotiate a connection before data transfer can start and it is a resilient protocol since it will repeatedly resend a packet until that packet is received by the intended recipient.
UDP is unreliable in a sense that it allows some packets to be lost in transit. Some applications of UDP are found in movie streaming where you can actually afford to lose a frame and not jeopardize movie quality. UDP does not need binding between the two parties and is often looked at as a light alternative to TCP.
A nice table is found here:TCP vs UDP
P.R.'s answer is mostly correct, but incomplete.
TCP is a reliable, connected stream protocol. Its view of data is that of a bidirectional stream of bytes between hosts: whatever bytes you send will arrive at the other end in the same order, at least as far as the application is concerned (the OS will rearrange packets if needed).
UDP is an unconnected datagram protocol. Its view of data is that of discrete datagrams, or messages, with no guarantee that these messages actually reach their recipient, or that they arrive in the order they were sent. It does guarantee that if a message arrives, it arrives in its entirety and without modification.
This website probably offers the simplest explanation to the actual difference of UDP and TCP. From implementation point of view, see this question.
For short answer: TCP works kind of like registered letter when UDP is kind of like ordinary letter - with the latter you never know whether the recipient got the packet you sent.
There are loads of helpful comparisons
chris is right!
One fancy link dropping out of google is: http://www.skullbox.net/tcpudp.php

When does a Java socket send an ack?

My question is that when a socket at the receiver-side sends an ack? At the time the application read the socket data or when the underlying layers get the data and put it in the buffer?
I want this because I want both side applications know whether the other side took the packet or not.
It's up to the operating system TCP stack when this happens, since TCP provides a stream to the application there's no guarenteed 1:1 correlation between the application doing read/writes and the packets sent on the wire and the TCP acks.
If you need to be assured the other side have received/processed your data, you need to build that into your application protocol - e.g. send a reply stating the data was received.
TCP ACKs are meant to acknowledge the TCP packets on the transmission layer not the application layer. Only your application can signal explicitly that it also has processed the data from the buffers.
TCP/IP (and therefor java sockets) will guarantee that you either successfully send the data OR get an error (exception in the case of java) eventually.

Resources