Retrieving tcp header using boost::asio::ip::tcp socket - sockets

I developed a TCP backend using boost asio and now I need to access the whole TCP packet (header + body). It is possible using TCP sockets?

Related

UDP vs TCP sockets requirements

I'm having some trouble understanding some key concept of the computer networking.
A UDP server usually only needs one socket, whereas a basic TCP server
needs two sockets. Why is that?
If a TCP server were to support n simultaneous
connections, each from a dierent client host, how many sockets would the
TCP server need?
If you can help me understand it I will be more than happy!
Thanks in advance.
hello i’ll try to explain this in a simple manner
TCP is a connection oriented protocol, while UDP is not.
what’s the difference?
In TCP it client and server must be connected first before sending and receiving msgs.
In UDP it can send and receive msgs without securing connection between client and server.
In terms of sockets (basic Tx and Rx)
UDP:
Client - 1 socket for Rx and Tx
Server - 1 socket for Rx and Tx
TCP
Client - 1 socket for Rx and Tx
Socket - 1 socket (main socket) and possibly n sockets
n - depends on how many clients will connect to the server

How to program a UDP webserver since HTTP normally uses TCP?

Here is my understanding of how a client-server HTTP server works.
The client creates a TCP socket connection to connect to the server and sends data.
The server creates a TCP socket connection to listen for incoming requests.
So it looks like both the client and the server need to agree on the use of the Transport protocol to use (in this case TCP). But if we want a website to work over UDP/QUIC protocol then we need both the client and the server to create a UDP socket connection. But some websites use TCP and others use UDP...
So does it mean it would need to look like this? To know beforehand which protocol a website uses?
if (URI == 'https://www.google.com') {
// Website that works over UDP
client.create.UDP.socket
client.sendData
server.create.UDP.socket
server.receive.data
} else {
// Website that works over TCP
client.create.TCP.socket
client.sendData
server.create.TCP.socket
server.receive.data
}
So the client needs to keep a record of which website uses TCP and which websites use UDP/QUIC and create that kind of socket to communicate with it?
If a protocol supports both TCP and UDP, the server listens both on the TCP port and the UDP port. The port number is generally the same, e.g. DNS uses TCP port 53 and UDP port 53.
Usually the client has a preference. Let's say it prefers TCP. The client will first try to connect with TCP. If the server does not respond, the client will retry with UDP. Alternatively, the server can respond over TCP but ask the client to switch to UDP. The client can then decide to continue with TCP or switch to UDP.
For QUIC 1 2, the browser will first connect using HTTP over TCP. The server will respond with a message stating that it also supports QUIC. If the browser also supports this protocol, the browser will reconnect to the server using QUIC.

Overhead of preserve tcp connection

I'm new to socket programming. I am wondering what is the internet and hardware overhead of create a TCP connection and let it be idle?
For example, There are1000 clients, each creates a tcp connection to a single server and after tcp connection established, at this point what is the internet or hardware overhead?
There is a 3-way TCP handshake that takes place to establish a TCP connection.
After the connection has been established, the only data that flows through the connection is what the applications send and, if enabled, TCP keep-alives (TCP segment with 0 payload).

how to have tcp act more like udp

is there a way to have tcp act more like udp? Im currently using lua sockets and have set the tcp no_delay option, is there a way to disable or set the acknowledgement to timeout?

Can TCP and UDP sockets use the same port?

First of all, is there any problem with using both UDP and TCP on the same server?
Secondly, can I use the same port number?
Yes, you can use the same port number for both TCP and UDP. Many protocols already do this, for example DNS works on udp/53 and tcp/53.
Technically the port pools for each protocol are completely independent, but for higher level protocols that can use either TCP or UDP it's convention that they default to the same port number.
When writing your server, bear in mind that the sequence of events for a TCP socket is much harder than for a UDP socket, since as well as the normal socket and bind calls you also have to listen and accept.
Furthermore that accept call will return a new socket and it's that socket that you'll then have to also poll for receive events. Your server should be prepared to continue accepting connections on the original socket whilst simultaneously servicing multiple clients each of which will be triggering receive events on their own sockets.
Firstly,there is no problem using both tcp and udp on the server.
Secondly,we can have both UDP and TCP requests on same port ,because each request is identified by a quintuple contained by source IP ,Destination IP, Source Port, Destination Port, PROTOCOL(as protocol can be TCP or UDP).