Reputation: 93
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" ?
Upvotes: 3
Views: 7228
Reputation: 548
A socket is a combination of an IP address and port number.
A packet is a layer 3 protocol data unit, or a piece of data associated with the network layer.
As far as the "progress" you mention, the OSI model is a helpful tool to describe the flow.
Each OSI model layer has an associated data unit. You can see above that a packet is a piece of data associated with the network layer. The network layer you're describing uses IP addresses to communicate.
Layer 4, or the Transport layer, uses port numbers for communication. A socket is the combination of port number and IP address.
The flow from the sender's perspective goes down the OSI model. Application data is surrounded with Transport headers (source and destination port numbers), then Network headers (source and destination IP addresses), then data-link headers (typically MAC addresses on an Ethernet LAN) and finally encoded as bits on the wire.
The flow from the recipient's perspective is just the reverse, climbing up the stack. Bits are received on the wire, then data is slowly "unpacked", removing headers. If the destination MAC matches the receiver, it strips those headers, if the IP matches, it strips those headers, if an open port is found, those headers are removed, finally resulting in unpacked application level data in the higher layers not shown here.
Hope this helps clarify.
Upvotes: 3
Reputation: 8300
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.
Upvotes: 5
Reputation: 1232
The socket is bound to your system to allow the communcation between two process.
The packet is a fragment of information that is send through the socket.
Upvotes: 0
Reputation: 409136
A socket is the abstraction you use to send packets of data.
Upvotes: 3