Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between a packet and a socket?

I just read "What is the difference between a port and a socket?" and seems socket is something to create connections. And then how about a packet? Is something sending between the connection? So the progress is "ip -> port -> socket -> sending packet" ?

like image 680
彭浩翔 Avatar asked Oct 31 '25 20:10

彭浩翔


1 Answers

A packet is a chunk of data. All IP networks send data in small chunks across the network. A socket(in relation to TCP/IP) is an abstraction built on top of this, that provides a reliable stream of data.

When using a socket, rather than deal with sending individual packets of data, you just send unlimited streams of data.
The socket implementation deals with splitting it into packets and sending it over the network and handles resending packets that are lost on the way.

like image 161
Magnus Avatar answered Nov 03 '25 21:11

Magnus